Merge "Need to check ndef before writing ndef." into gingerbread
diff --git a/core/java/android/nfc/technology/Ndef.java b/core/java/android/nfc/technology/Ndef.java
index c45c97d..cd12249 100644
--- a/core/java/android/nfc/technology/Ndef.java
+++ b/core/java/android/nfc/technology/Ndef.java
@@ -148,17 +148,23 @@
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);