First pass at advanced NFC tag dispatching APIs and other cleanup.
Change-Id: I022fcd481274a2f68d93218026e77551cfae8cae
This commit is contained in:
@ -34,9 +34,9 @@ interface INfcTag
|
||||
|
||||
int getLastError(int nativeHandle);
|
||||
|
||||
NdefMessage read(int nativeHandle);
|
||||
int write(int nativeHandle, in NdefMessage msg);
|
||||
int makeReadOnly(int nativeHandle);
|
||||
int getModeHint(int nativeHandle);
|
||||
NdefMessage ndefRead(int nativeHandle);
|
||||
int ndefWrite(int nativeHandle, in NdefMessage msg);
|
||||
int ndefMakeReadOnly(int nativeHandle);
|
||||
boolean ndefIsWritable(int nativeHandle);
|
||||
int formatNdef(int nativeHandle, in byte[] key);
|
||||
}
|
||||
|
@ -36,6 +36,32 @@ import android.util.Log;
|
||||
public final class NfcAdapter {
|
||||
private static final String TAG = "NFC";
|
||||
|
||||
/**
|
||||
* Intent to start an activity when a tag with NDEF payload is discovered.
|
||||
* If the tag has and NDEF payload this intent is started before
|
||||
* {@link #ACTION_TECHNOLOGY_DISCOVERED}.
|
||||
*
|
||||
* If any activities respond to this intent neither
|
||||
* {@link #ACTION_TECHNOLOGY_DISCOVERED} or {@link #ACTION_TAG_DISCOVERED} will be started.
|
||||
* @hide
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
|
||||
public static final String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
|
||||
|
||||
/**
|
||||
* Intent to started when a tag is discovered. The data URI is formated as
|
||||
* {@code vnd.android.nfc://tag/} with the path having a directory entry for each technology
|
||||
* in the {@link Tag#getTechnologyList()} is ascending order.
|
||||
*
|
||||
* This intent is started after {@link #ACTION_NDEF_DISCOVERED} and before
|
||||
* {@link #ACTION_TAG_DISCOVERED}
|
||||
*
|
||||
* If any activities respond to this intent {@link #ACTION_TAG_DISCOVERED} will not be started.
|
||||
* @hide
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
|
||||
public static final String ACTION_TECHNOLOGY_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
|
||||
|
||||
/**
|
||||
* Intent to start an activity when a tag is discovered.
|
||||
*/
|
||||
|
@ -79,7 +79,7 @@ public final class Ndef extends BasicTagTechnology {
|
||||
public NdefMessage getNdefMessage() throws IOException, FormatException {
|
||||
try {
|
||||
int serviceHandle = mTag.getServiceHandle();
|
||||
NdefMessage msg = mTagService.read(serviceHandle);
|
||||
NdefMessage msg = mTagService.ndefRead(serviceHandle);
|
||||
if (msg == null) {
|
||||
int errorCode = mTagService.getLastError(serviceHandle);
|
||||
switch (errorCode) {
|
||||
@ -119,7 +119,6 @@ public final class Ndef extends BasicTagTechnology {
|
||||
* Provides a hint on whether writes are likely to succeed.
|
||||
* <p>Requires {@link android.Manifest.permission#NFC} permission.
|
||||
* @return true if write is likely to succeed
|
||||
* @throws IOException if the target is lost or connection closed
|
||||
*/
|
||||
public boolean isWritable() {
|
||||
return (mCardState == NDEF_MODE_READ_WRITE);
|
||||
@ -132,7 +131,7 @@ public final class Ndef extends BasicTagTechnology {
|
||||
*/
|
||||
public void writeNdefMessage(NdefMessage msg) throws IOException, FormatException {
|
||||
try {
|
||||
int errorCode = mTagService.write(mTag.getServiceHandle(), msg);
|
||||
int errorCode = mTagService.ndefWrite(mTag.getServiceHandle(), msg);
|
||||
switch (errorCode) {
|
||||
case ErrorCodes.SUCCESS:
|
||||
break;
|
||||
@ -169,7 +168,7 @@ public final class Ndef extends BasicTagTechnology {
|
||||
*/
|
||||
public boolean makeReadonly() throws IOException {
|
||||
try {
|
||||
int errorCode = mTagService.makeReadOnly(mTag.getServiceHandle());
|
||||
int errorCode = mTagService.ndefMakeReadOnly(mTag.getServiceHandle());
|
||||
switch (errorCode) {
|
||||
case ErrorCodes.SUCCESS:
|
||||
return true;
|
||||
|
@ -73,7 +73,7 @@ public final class NdefFormatable extends BasicTagTechnology {
|
||||
// Should not happen
|
||||
throw new IOException();
|
||||
}
|
||||
errorCode = mTagService.write(serviceHandle, firstMessage);
|
||||
errorCode = mTagService.ndefWrite(serviceHandle, firstMessage);
|
||||
switch (errorCode) {
|
||||
case ErrorCodes.SUCCESS:
|
||||
break;
|
||||
|
@ -39,42 +39,32 @@ public interface TagTechnology {
|
||||
/**
|
||||
* This object is an instance of {@link NfcF}
|
||||
*/
|
||||
public static final int NFC_F = 11;
|
||||
public static final int NFC_F = 4;
|
||||
|
||||
/**
|
||||
* This object is an instance of {@link NfcV}
|
||||
*/
|
||||
public static final int NFC_V = 21;
|
||||
public static final int NFC_V = 5;
|
||||
|
||||
/**
|
||||
* This object is an instance of {@link Ndef}
|
||||
*/
|
||||
public static final int NDEF = 101;
|
||||
public static final int NDEF = 6;
|
||||
|
||||
/**
|
||||
* This object is an instance of {@link NdefFormatable}
|
||||
*/
|
||||
public static final int NDEF_FORMATABLE = 110;
|
||||
public static final int NDEF_FORMATABLE = 7;
|
||||
|
||||
/**
|
||||
* This object is an instance of {@link MifareClassic}
|
||||
*/
|
||||
public static final int MIFARE_CLASSIC = 200;
|
||||
|
||||
/**
|
||||
* A Mifare Classic tag with NDEF data
|
||||
*/
|
||||
public static final int MIFARE_CLASSIC_NDEF = 201;
|
||||
public static final int MIFARE_CLASSIC = 8;
|
||||
|
||||
/**
|
||||
* This object is an instance of {@link MifareUltralight}
|
||||
*/
|
||||
public static final int MIFARE_ULTRALIGHT = 202;
|
||||
|
||||
/**
|
||||
* A Mifare DESFire tag
|
||||
*/
|
||||
public static final int MIFARE_DESFIRE = 203;
|
||||
public static final int MIFARE_ULTRALIGHT = 9;
|
||||
|
||||
/**
|
||||
* Returns the technology type for this tag connection.
|
||||
|
Reference in New Issue
Block a user