diff --git a/api/current.txt b/api/current.txt index 3c60b02fb9f71..370fa8fc58d8e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -24246,6 +24246,7 @@ package android.nfc { public final class Tag implements android.os.Parcelable { method public int describeContents(); + method public boolean done(int); method public byte[] getId(); method public java.lang.String[] getTechList(); method public void writeToParcel(android.os.Parcel, int); diff --git a/api/system-current.txt b/api/system-current.txt index d5b7a185509ed..cf6b87486270b 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -26246,6 +26246,7 @@ package android.nfc { public final class Tag implements android.os.Parcelable { method public int describeContents(); + method public boolean done(int); method public byte[] getId(); method public java.lang.String[] getTechList(); method public void writeToParcel(android.os.Parcel, int); diff --git a/api/test-current.txt b/api/test-current.txt index 4060b30c6a6a8..d3a6b3ae458d2 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -24254,6 +24254,7 @@ package android.nfc { public final class Tag implements android.os.Parcelable { method public int describeContents(); + method public boolean done(int); method public byte[] getId(); method public java.lang.String[] getTechList(); method public void writeToParcel(android.os.Parcel, int); diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl index 3ac1dcc272b74..26d2bec761f8f 100644 --- a/core/java/android/nfc/INfcTag.aidl +++ b/core/java/android/nfc/INfcTag.aidl @@ -25,13 +25,13 @@ import android.nfc.TransceiveResult; */ interface INfcTag { - int close(int nativeHandle); int connect(int nativeHandle, int technology); int reconnect(int nativeHandle); int[] getTechList(int nativeHandle); boolean isNdef(int nativeHandle); boolean isPresent(int nativeHandle); TransceiveResult transceive(int nativeHandle, in byte[] data, boolean raw); + boolean done(int nativeHandle, int debounceMs); NdefMessage ndefRead(int nativeHandle); int ndefWrite(int nativeHandle, in NdefMessage msg); diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index 154d5a11db9e4..40d5a8db83b41 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -214,6 +214,42 @@ public final class Tag implements Parcelable { return techIntList; } + /** + * Signals that you are no longer interested in communicating with this tag + * for as long as it remains in range. + * + * All future attempted communication to this tag will fail with {@link IOException}. + * The NFC controller will be put in a low-power polling mode, allowing the device + * to save power in cases where it's "attached" to a tag all the time (eg a tag in + * car dock). + * + * Additionally the debounceMs parameter allows you to specify for how long the tag needs + * to have gone out of range, before it will be dispatched again. + * + * Note: the NFC controller typically polls at a pretty slow interval (100 - 500 ms). + * This means that if the tag repeatedly goes in and out of range (for example, in + * case of a flaky connection), and the controller happens to poll every time the + * tag is out of range, it *will* re-dispatch the tag after debounceMs, despite the tag + * having been "in range" during the interval. + * + * Note 2: if a tag with another UID is detected after this API is called, its effect + * will be cancelled; if this tag shows up before the amount of time specified in + * debounceMs, it will be dispatched again. + * + * Note 3: some tags have a random UID, in which case this API won't work. + * + * @param debounceMs minimum amount of time the tag needs to be out of range before being + * dispatched again. + * @return false if the Tag couldn't be found (or has gone out of range), true otherwise + */ + public boolean done(int debounceMs) { + try { + return mTagService.done(getServiceHandle(), debounceMs); + } catch (RemoteException e) { + return false; + } + } + private static HashMap getTechStringToCodeMap() { HashMap techStringToCodeMap = new HashMap();