Skip to content

Instantly share code, notes, and snippets.

@salmangadit
Created June 25, 2013 04:17
Show Gist options
  • Save salmangadit/5855899 to your computer and use it in GitHub Desktop.
Save salmangadit/5855899 to your computer and use it in GitHub Desktop.
Android intent resolution for Mifare Ultralight
void resolveIntent(Intent intent) {
// 1) Parse the intent and get the action that triggered this intent
String action = intent.getAction();
// 2) Check if it was triggered by a tag discovered interruption.
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
// 3) Get an instance of the TAG from the NfcAdapter
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
// 4) Get an instance of the Mifare ultralight card from this TAG
// intent
MifareUltralight mfc = MifareUltralight.get(tagFromIntent);
// MifareClassic mfc = MifareClassic.get(tagFromIntent);
byte[] data;
try { // 5.1) Connect to card
mfc.connect();
byte[] payload = mfc.readPages(0);
// getHexString(payload, payload.length)
uid = new String(getHexString(payload, payload.length));
Log.v(TAG, uid);
} catch (IOException e) {
Log.e(TAG,
"IOException while writing MifareUltralight message...",
e);
} finally {
if (mfc != null) {
try {
mfc.close();
//invokeRestAPI();
} catch (IOException e) {
Log.e(TAG, "Error closing tag...", e);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment