diff options
author | Martijn Coenen <maco@google.com> | 2011-06-02 16:02:00 -0700 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-06-08 23:26:42 +0200 |
commit | 2dcae567ab56285bc70b6857c4f3c87df09641b8 (patch) | |
tree | 66ba635f803d8ea339ccf62482a514f3bf0c7587 /core/java/android/nfc | |
parent | 9eb5847777b317991a44c01b901f35d99485c733 (diff) | |
download | frameworks_base-2dcae567ab56285bc70b6857c4f3c87df09641b8.zip frameworks_base-2dcae567ab56285bc70b6857c4f3c87df09641b8.tar.gz frameworks_base-2dcae567ab56285bc70b6857c4f3c87df09641b8.tar.bz2 |
Added support for rediscovering a Tag (API).
Bug: 3378764
Change-Id: I4697b814337270c4458ca2b8ce358de315904777
Diffstat (limited to 'core/java/android/nfc')
-rw-r--r-- | core/java/android/nfc/INfcTag.aidl | 2 | ||||
-rw-r--r-- | core/java/android/nfc/Tag.java | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl index 31d004e..b66035f 100644 --- a/core/java/android/nfc/INfcTag.aidl +++ b/core/java/android/nfc/INfcTag.aidl @@ -17,6 +17,7 @@ package android.nfc; import android.nfc.NdefMessage; +import android.nfc.Tag; import android.nfc.TransceiveResult; /** @@ -40,6 +41,7 @@ interface INfcTag int ndefMakeReadOnly(int nativeHandle); boolean ndefIsWritable(int nativeHandle); int formatNdef(int nativeHandle, in byte[] key); + Tag rediscover(int nativehandle); void setIsoDepTimeout(int timeout); void setFelicaTimeout(int timeout); diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index b676975..54583d6 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -30,7 +30,9 @@ import android.nfc.tech.TagTechnology; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; +import android.os.RemoteException; +import java.io.IOException; import java.util.Arrays; /** @@ -233,6 +235,50 @@ public final class Tag implements Parcelable { return mTechStringList; } + /** + * Rediscover the technologies available on this tag. + * <p> + * The technologies that are available on a tag may change due to + * operations being performed on a tag. For example, formatting a + * tag as NDEF adds the {@link Ndef} technology. The {@link rediscover} + * method reenumerates the available technologies on the tag + * and returns a new {@link Tag} object containing these technologies. + * <p> + * You may not be connected to any of this {@link Tag}'s technologies + * when calling this method. + * This method guarantees that you will be returned the same Tag + * if it is still in the field. + * <p>May cause RF activity and may block. Must not be called + * from the main application thread. A blocked call will be canceled with + * {@link IOException} by calling {@link #close} from another thread. + * <p>Does not remove power from the RF field, so a tag having a random + * ID should not change its ID. + * @return the rediscovered tag object. + * @throws IOException if the tag cannot be rediscovered + * @hide + */ + // TODO See if we need TagLostException + // TODO Unhide for ICS + // TODO Update documentation to make sure it matches with the final + // implementation. + public Tag rediscover() throws IOException { + if (getConnectedTechnology() != -1) { + throw new IllegalStateException("Close connection to the technology first!"); + } + + try { + Tag newTag = mTagService.rediscover(getServiceHandle()); + if (newTag != null) { + return newTag; + } else { + throw new IOException("Failed to rediscover tag"); + } + } catch (RemoteException e) { + throw new IOException("NFC service dead"); + } + } + + /** @hide */ public boolean hasTech(int techType) { for (int tech : mTechList) { |