List of usage examples for android.nfc NfcAdapter EXTRA_ID
String EXTRA_ID
To view the source code for android.nfc NfcAdapter EXTRA_ID.
Click Source Link
From source file:org.schabi.terminightor.NightKillerActivity.java
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); byte[] nfcId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); if (nfcId != null) { if (Arrays.equals(nfcId, expectedNfcId) || ignoreNfcTagId) { Log.d(TAG, "Send kill alarm"); Intent killAlarmIntent = new Intent(NightKillerService.ACTION_KILL_ALARM); LocalBroadcastManager.getInstance(this).sendBroadcast(killAlarmIntent); finish();/*from w ww . ja v a2 s .co m*/ } else { Toast.makeText(this, R.string.wrongTagToast, Toast.LENGTH_SHORT).show(); Log.d(TAG, "Expected: " + Arrays.toString(expectedNfcId)); Log.d(TAG, "Given: " + Arrays.toString(nfcId)); } } }
From source file:mai.whack.StickyNotesActivity.java
private void onDataRead(Intent intent) { // Parse the intent NdefMessage[] msgs = null;/* www .j a va 2 s . com*/ String action = intent.getAction(); byte[] tagId = null; if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } } else { Log.d(TAG, "Unknown intent."); finish(); } String msg = new String(msgs[0].getRecords()[0].getPayload()); mHttpGetThread = new HttpGetThread("http://192.168.1.192/store/" + toHex(tagId)); mHttpGetThread.start(); // mHttpPostThread = new HttpPostThread("aaaaa", "bbbbb", "sdgsdfdsfs"); // mHttpPostThread.start(); }
From source file:se.anyro.nfc_reader.TagViewer.java
private void resolveIntent(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs;// w ww . j a v a2s.c o m if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; // magic happens here processReadTag((NdefMessage) rawMsgs[i]); } } else { // Unknown tag type byte[] empty = new byte[0]; byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); byte[] payload = dumpTagData(tag).getBytes(); NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, id, payload); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } // Setup the views buildTagViews(msgs); } }
From source file:mai.whack.StickyNotesActivity.java
private void onDataWrite(Intent intent) { byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); Cursor mCur = this.managedQuery(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, "DATE"); // mCur.moveToFirst(); if (mCur.moveToLast() && mCur.getCount() > 0) { String url = mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX); mHttpPostThread = new HttpPostThread(toHex(tagId), "tabs", url); mHttpPostThread.start();//from w w w. j a v a2 s. c o m } }
From source file:nl.hnogames.domoticz.NFCSettingsActivity.java
@Override protected void onNewIntent(Intent intent) { if (intent.getAction().equals(NfcAdapter.ACTION_TAG_DISCOVERED) && !busyWithTag) { boolean newTagFound = true; busyWithTag = true;//from w ww . j av a 2s . co m final String tagID = UsefulBits.ByteArrayToHexString(intent.getByteArrayExtra(NfcAdapter.EXTRA_ID)); if (nfcList != null && nfcList.size() > 0) { for (NFCInfo n : nfcList) { if (n.getId().equals(tagID)) newTagFound = false; } } if (newTagFound) { UsefulBits.showSnackbar(this, coordinatorLayout, getString(R.string.nfc_tag_found) + ": " + tagID, Snackbar.LENGTH_SHORT); new MaterialDialog.Builder(this).title(R.string.nfc_tag_found).content(R.string.nfc_tag_name) .inputType(InputType.TYPE_CLASS_TEXT) .input(R.string.category_nfc, 0, new MaterialDialog.InputCallback() { @Override public void onInput(@NonNull MaterialDialog dialog, CharSequence input) { if (!UsefulBits.isEmpty(String.valueOf(input))) { UsefulBits.showSnackbar(NFCSettingsActivity.this, coordinatorLayout, getString(R.string.nfc_saved) + ": " + input, Snackbar.LENGTH_SHORT); NFCInfo newNFC = new NFCInfo(); newNFC.setId(tagID); newNFC.setName(String.valueOf(input)); updateNFC(newNFC); } busyWithTag = false; } }).show(); } else { UsefulBits.showSnackbar(NFCSettingsActivity.this, coordinatorLayout, R.string.nfc_exists, Snackbar.LENGTH_SHORT); busyWithTag = false; } } }
From source file:net.kazzz.NFCTagReader.java
@Override public void onTagDiscovered(Intent intent, Parcelable nfcTag, AbstractNfcTagFragment fragment) { //TextView tv_tag = (TextView) findViewById(R.id.result_tv); Button btnRead = (Button) findViewById(R.id.btn_read); btnRead.setOnClickListener(this); Button btnHistory = (Button) findViewById(R.id.btn_hitory); btnHistory.setOnClickListener(this); btnHistory.setEnabled(false);//from ww w . j av a2 s. co m Button btnWrite = (Button) findViewById(R.id.btn_write); btnWrite.setOnClickListener(this); btnWrite.setEnabled(false); Button btnInout = (Button) findViewById(R.id.btn_inout); btnInout.setOnClickListener(this); btnInout.setEnabled(false); try { mLastFragment = fragment; //? if (mLastFragment instanceof NfcFeliCaTagFragment) { NfcFeliCaTagFragment nff = (NfcFeliCaTagFragment) mLastFragment; boolean isFeliCatLite = nff.isFeliCaLite(); try { FeliCaLib.IDm idm = new FeliCaLib.IDm(intent.getByteArrayExtra(NfcAdapter.EXTRA_ID)); if (idm == null) { throw new FeliCaException("Felica IDm ?????????"); } btnHistory.setEnabled(!isFeliCatLite); btnWrite.setEnabled(isFeliCatLite); btnRead.performClick(); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, e.toString()); } btnHistory.setEnabled(!isFeliCatLite); btnWrite.setEnabled(isFeliCatLite); } else { btnRead.performClick(); btnHistory.setEnabled(false); btnWrite.setEnabled(true); } } catch (Exception e) { e.printStackTrace(); Log.e(TAG, e.toString()); } }
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * On create, process NDEF message with its intent action * /*from w w w. j ava2 s . c o m*/ * @param intent */ private String resolveIntent(Intent intent) { Log.d(CLASSNAME, "resolveIntent is called intent:" + intent.toString()); String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[0]; byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); byte[] payload = dumpTagData(tag).getBytes(); NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, id, payload); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } return processNdefMessageArray(msgs); } return IParsedNdefCommand.COMMAND_UNKNOWN; }