Skip to content

Commit

Permalink
workaround for ICS bug of sometimes returning null from mTag.getTagSe…
Browse files Browse the repository at this point in the history
…rvice()
  • Loading branch information
zonpantli committed Mar 3, 2012
1 parent 6644e82 commit c2bdb24
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/com/chariotsolutions/nfc/plugin/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ static JSONObject ndefToJSON(Ndef ndef) {
json.put("type", translateType(ndef.getType()));
json.put("maxSize", ndef.getMaxSize());
json.put("isWritable", ndef.isWritable());
json.put("canMakeReadOnly", ndef.canMakeReadOnly());
json.put("ndefMessage", messageToJSON(ndef.getCachedNdefMessage()));
// Workaround for bug in ICS (Android 4.0 and 4.0.1) where
// mTag.getTagService(); of the Ndef object sometimes returns null
// see http://issues.mroland.at/index.php?do=details&task_id=47
try {
json.put("canMakeReadOnly", ndef.canMakeReadOnly());
} catch (NullPointerException e) {
json.put("canMakeReadOnly", null);
}
} catch (JSONException e) {
Log.e(TAG, "Failed to convert ndef into json: " + ndef.toString(), e);
}
Expand Down

0 comments on commit c2bdb24

Please sign in to comment.