Methods Summary |
---|
void | checkConnected()Internal helper to throw IllegalStateException if the technology isn't connected
if ((mTag.getConnectedTechnology() != mSelectedTechnology) ||
(mTag.getConnectedTechnology() == -1)) {
throw new IllegalStateException("Call connect() first!");
}
|
public void | close()
try {
/* Note that we don't want to physically disconnect the tag,
* but just reconnect to it to reset its state
*/
mTag.getTagService().resetTimeouts();
mTag.getTagService().reconnect(mTag.getServiceHandle());
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
} finally {
mIsConnected = false;
mTag.setTechnologyDisconnected();
}
|
public void | connect()
try {
int errorCode = mTag.getTagService().connect(mTag.getServiceHandle(),
mSelectedTechnology);
if (errorCode == ErrorCodes.SUCCESS) {
// Store this in the tag object
mTag.setConnectedTechnology(mSelectedTechnology);
mIsConnected = true;
} else if (errorCode == ErrorCodes.ERROR_NOT_SUPPORTED) {
throw new UnsupportedOperationException("Connecting to " +
"this technology is not supported by the NFC " +
"adapter.");
} else {
throw new IOException();
}
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
throw new IOException("NFC service died");
}
|
int | getMaxTransceiveLengthInternal()Internal getMaxTransceiveLength()
try {
return mTag.getTagService().getMaxTransceiveLength(mSelectedTechnology);
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
return 0;
}
|
public android.nfc.Tag | getTag()
return mTag;
|
public boolean | isConnected()
if (!mIsConnected) {
return false;
}
try {
return mTag.getTagService().isPresent(mTag.getServiceHandle());
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
return false;
}
|
public void | reconnect()
if (!mIsConnected) {
throw new IllegalStateException("Technology not connected yet");
}
try {
int errorCode = mTag.getTagService().reconnect(mTag.getServiceHandle());
if (errorCode != ErrorCodes.SUCCESS) {
mIsConnected = false;
mTag.setTechnologyDisconnected();
throw new IOException();
}
} catch (RemoteException e) {
mIsConnected = false;
mTag.setTechnologyDisconnected();
Log.e(TAG, "NFC service dead", e);
throw new IOException("NFC service died");
}
|
byte[] | transceive(byte[] data, boolean raw)Internal transceive
checkConnected();
try {
TransceiveResult result = mTag.getTagService().transceive(mTag.getServiceHandle(),
data, raw);
if (result == null) {
throw new IOException("transceive failed");
} else {
return result.getResponseOrThrow();
}
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
throw new IOException("NFC service died");
}
|