Commit 96bba350 authored by kirk's avatar kirk

fix various lint warnings; add AAR when writing tags

parent 3888bc8f
......@@ -2,6 +2,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/write_tag_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:padding="@dimen/qr_code_padding" >
</FrameLayout>
......@@ -4,5 +4,6 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="row_padding">10dp</dimen>
<dimen name="qr_code_padding">10dp</dimen>
</resources>
......@@ -2,7 +2,6 @@
<resources>
<string name="app_name">WyFy</string>
<string name="action_settings">Settings</string>
<string name="ssid_label">SSID</string>
<string name="password_label">Password</string>
<string name="security_label">Security</string>
......@@ -12,13 +11,11 @@
<string name="hidden_label">Hidden</string>
<string name="title_activity_write_tag">WriteTagActivity</string>
<string name="tap_tag">Tap tag to write&#8230;</string>
<string name="error_procesing_tag">Error procesing tag</string>
<string name="incompatible_tag">Incompatible tag; please try another</string>
<string name="error_formatting_tag">Error formatting tag</string>
<string name="error_writing_tag">Error writing tag</string>
<string name="read_only_tag">Read-only tag; please try another</string>
<string name="tag_size_exceeded">Message size %1$d exceeds tag size %2$d; please try another</string>
<string name="success_writing_tag">Successfully wrote to tag</string>
<string name="write_tag_label">Write tag&#8230;</string>
<string name="successfully_added_wifi">Successfully added %1$s</string>
<string name="successfully_enabled_wifi">Successfully enabled %1$s</string>
......@@ -32,7 +29,7 @@
<string name="unrecognized_result_code">Unrecognized result code %1$d</string>
<string name="canceled">Canceled</string>
<string name="unrecognized_connection_outcome">Unrecognized connection outcome %1$s</string>
<string name="null_message">Status ok but message is null</string>
<string name="null_message">Status OK but message is null</string>
<string name="empty_message">Empty message</string>
<string name="unparseable_payload">Unparseable payload</string>
......
......@@ -112,7 +112,9 @@ public final class WriteTagActivity extends NdefWriterActivity {
protected NdefMessage createNdefMessage(NdefMessage currentMessage) {
NdefRecord record = createUri(uri);
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[] { record });
NdefRecord aar = createAar(getClass().getPackage());
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[] { record,
aar });
return ndefMessage;
}
......
......@@ -32,6 +32,59 @@ import android.util.Log;
*/
public abstract class NdefWriterActivity extends NdefReaderActivity {
/**
* Create a AAR {@link NdefRecord} for the given {@link Package}
*
* @param pkg
* the {@link Package}
*
* @return AAR {@link NdefRecord}
*/
public static NdefRecord createAar(Package pkg) {
return createAar(pkg.getName());
}
/**
* Create a AAR {@link NdefRecord} for the given {@link Package} name
*
* <p>
* Even though AAR records will only be used by devices running ice cream
* sandwich or later, this method uses API's available since gingerbread mr1
* to create them. They will be benignly ignored by older devices when
* reading tags that include them.
* </p>
*
* <p>
* TODO: inferred this format by inspecting some actual AAR records created
* using {@link NdefRecord#createApplicationRecord(String)} (that only
* became available in ice cream sandwich). Should investigate if there is,
* somewhere, an official public specification.
* </p>
*
* @param pkg
* the {@link Package} name
*
* @return AAR {@link NdefRecord}
*/
public static NdefRecord createAar(String pkg) {
try {
byte[] type = "android.com:pkg".getBytes("US-ASCII"); //$NON-NLS-1$//$NON-NLS-2$
byte[] payload = pkg.getBytes("US-ASCII"); //$NON-NLS-1$
return new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, type, null,
payload);
} catch (UnsupportedEncodingException e) {
Log.e(NdefWriterActivity.class.getName(), "createAar", e); //$NON-NLS-1$
throw new IllegalArgumentException(e);
}
}
/**
* Return MIME {@link NdefRecord}
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment