From a37fcbce59c8a746f641936b4de99867dbfabac9 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Fri, 5 Aug 2011 09:56:17 -0700 Subject: [PATCH] Add Android app RTD type and convenience method. Change-Id: I4e6351c86a0062efc9a9f90e75c04f6520e50c4f --- core/java/android/nfc/NdefRecord.java | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java index b668f30736029..6ba34515c9f0f 100644 --- a/core/java/android/nfc/NdefRecord.java +++ b/core/java/android/nfc/NdefRecord.java @@ -21,6 +21,7 @@ import android.os.Parcel; import android.os.Parcelable; import java.lang.UnsupportedOperationException; +import java.nio.charset.Charset; import java.nio.charset.Charsets; import java.util.Arrays; @@ -139,6 +140,22 @@ public final class NdefRecord implements Parcelable { */ public static final byte[] RTD_HANDOVER_SELECT = {0x48, 0x73}; // "Hs" + /** + * RTD Android app type. For use with TNF_EXTERNAL. + *

+ * The payload of a record with type RTD_ANDROID_APP + * should be the package name identifying an application. + * Multiple RTD_ANDROID_APP records may be included + * in a single {@link NdefMessage}. + *

+ * Use {@link #createApplicationRecord(String)} to create + * RTD_ANDROID_APP records. + * @hide + */ + // TODO unhide for ICS + // TODO recheck docs + public static final byte[] RTD_ANDROID_APP = "android.com:pkg".getBytes(); + private static final byte FLAG_MB = (byte) 0x80; private static final byte FLAG_ME = (byte) 0x40; private static final byte FLAG_CF = (byte) 0x20; @@ -332,6 +349,29 @@ public final class NdefRecord implements Parcelable { return Uri.parse(new String(fullUri, Charsets.UTF_8)); } + /** + * Creates an Android application NDEF record. + *

+ * When an Android device dispatches an {@link NdefMessage} + * containing one or more Android application records, + * the applications contained in those records will be the + * preferred target for the NDEF_DISCOVERED intent, in + * the order in which they appear in the {@link NdefMessage}. + *

+ * If none of the applications are installed on the device, + * a Market link will be opened to the first application. + *

+ * Note that Android application records do not overrule + * applications that have called {@link NfcAdapter#enableForegroundDispatch}. + * @hide + */ + // TODO unhide for ICS + // TODO recheck javadoc - should mention this works from ICS only + public static NdefRecord createApplicationRecord(String packageName) { + return new NdefRecord(TNF_EXTERNAL_TYPE, RTD_ANDROID_APP, new byte[] {}, + packageName.getBytes(Charsets.US_ASCII)); + } + /** * Creates an NDEF record of well known type URI. */