Skip to content

Commit 2976da0

Browse files
author
Martijn Coenen
committed
Allow formatting a tag as NDEF without a message.
Change-Id: I53a219eec17450b2d0ddc42556f0b930d9b34615
1 parent 5fa4729 commit 2976da0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

core/java/android/nfc/tech/NdefFormatable.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ public void formatReadOnly(NdefMessage firstMessage) throws IOException, FormatE
137137
throw new IOException();
138138
}
139139
// Now check and see if the format worked
140-
if (tagService.isNdef(serviceHandle)) {
140+
if (!tagService.isNdef(serviceHandle)) {
141+
throw new IOException();
142+
}
143+
144+
// Write a message, if one was provided
145+
if (firstMessage != null) {
141146
errorCode = tagService.ndefWrite(serviceHandle, firstMessage);
142147
switch (errorCode) {
143148
case ErrorCodes.SUCCESS:
@@ -150,9 +155,8 @@ public void formatReadOnly(NdefMessage firstMessage) throws IOException, FormatE
150155
// Should not happen
151156
throw new IOException();
152157
}
153-
} else {
154-
throw new IOException();
155158
}
159+
156160
// optionally make read-only
157161
if (makeReadOnly) {
158162
errorCode = tagService.ndefMakeReadOnly(serviceHandle);

0 commit comments

Comments
 (0)