Add Android app RTD type and convenience method.

Change-Id: I4e6351c86a0062efc9a9f90e75c04f6520e50c4f
diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java
index b668f30..6ba3451 100644
--- a/core/java/android/nfc/NdefRecord.java
+++ b/core/java/android/nfc/NdefRecord.java
@@ -21,6 +21,7 @@
 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 static final byte[] RTD_HANDOVER_SELECT = {0x48, 0x73}; // "Hs"
 
+    /**
+     * RTD Android app type. For use with TNF_EXTERNAL.
+     * <p>
+     * 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}.
+     * <p>
+     * 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;
@@ -333,6 +350,29 @@
     }
 
     /**
+     * Creates an Android application NDEF record.
+     * <p>
+     * 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}.
+     * <p>
+     * If none of the applications are installed on the device,
+     * a Market link will be opened to the first application.
+     * <p>
+     * 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.
      */
     public static NdefRecord createUri(Uri uri) {