Example usage for android.nfc.tech Ndef toString

List of usage examples for android.nfc.tech Ndef toString

Introduction

In this page you can find the example usage for android.nfc.tech Ndef toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:Main.java

static JSONObject ndefToJSON(Ndef ndef) {
    JSONObject json = new JSONObject();

    if (ndef != null) {
        try {/*from w w  w . j av a2s .  c  om*/

            Tag tag = ndef.getTag();
            // tag is going to be null for NDEF_FORMATABLE until NfcUtil.parseMessage is refactored
            if (tag != null) {
                json.put("id", byteArrayToJSON(tag.getId()));
                json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
            }

            json.put("type", translateType(ndef.getType()));
            json.put("maxSize", ndef.getMaxSize());
            json.put("isWritable", ndef.isWritable());
            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", JSONObject.NULL);
            }
        } catch (JSONException e) {
            Log.e(TAG, "Failed to convert ndef into json: " + ndef.toString(), e);
        }
    }
    return json;
}