diff options
| -rw-r--r-- | core/java/android/nfc/technology/Ndef.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/core/java/android/nfc/technology/Ndef.java b/core/java/android/nfc/technology/Ndef.java index c45c97d28237..cd1224912aba 100644 --- a/core/java/android/nfc/technology/Ndef.java +++ b/core/java/android/nfc/technology/Ndef.java @@ -148,17 +148,23 @@ public final class Ndef extends BasicTagTechnology { checkConnected(); try { - int errorCode = mTagService.ndefWrite(mTag.getServiceHandle(), msg); - switch (errorCode) { - case ErrorCodes.SUCCESS: - break; - case ErrorCodes.ERROR_IO: - throw new IOException(); - case ErrorCodes.ERROR_INVALID_PARAM: - throw new FormatException(); - default: - // Should not happen - throw new IOException(); + int serviceHandle = mTag.getServiceHandle(); + if (mTagService.isNdef(serviceHandle)) { + int errorCode = mTagService.ndefWrite(serviceHandle, msg); + switch (errorCode) { + case ErrorCodes.SUCCESS: + break; + case ErrorCodes.ERROR_IO: + throw new IOException(); + case ErrorCodes.ERROR_INVALID_PARAM: + throw new FormatException(); + default: + // Should not happen + throw new IOException(); + } + } + else { + throw new IOException("Tag is not ndef"); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); |