List of usage examples for android.nfc NfcAdapter EXTRA_TAG
String EXTRA_TAG
To view the source code for android.nfc NfcAdapter EXTRA_TAG.
Click Source Link
From source file:jp.co.brilliantservice.android.writertdtext.HomeActivity.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); String action = intent.getAction(); if (TextUtils.isEmpty(action)) return;//from w ww . jav a 2 s . c o m if (!action.equals(NfcAdapter.ACTION_TECH_DISCOVERED)) return; // NdefMessage? String languageCode = "en"; String text = String.format("Hello, World.(%s)", DATE_FORMAT.format(System.currentTimeMillis())); NdefMessage message = createTextMessage(text, languageCode); // ?????????? Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); List<String> techList = Arrays.asList(tag.getTechList()); if (techList.contains(Ndef.class.getName())) { Ndef ndef = Ndef.get(tag); writeNdefToNdefTag(ndef, message); Toast.makeText(getApplicationContext(), "wrote NDEF to NDEF tag", Toast.LENGTH_SHORT).show(); } else if (techList.contains(NdefFormatable.class.getName())) { NdefFormatable ndef = NdefFormatable.get(tag); writeNdefToNdefFormatable(ndef, message); Toast.makeText(getApplicationContext(), "wrote NDEF to NDEFFormatable tag", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "NDEF Not Supported", Toast.LENGTH_SHORT).show(); } }
From source file:org.openhab.habdroid.ui.OpenHABWriteTagActivity.java
@Override public void onNewIntent(Intent intent) { if (mSitemapPage == null) { return;/*from ww w . j a v a 2s. co m*/ } Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); //do something with tagFromIntent Log.d(TAG, "NFC TAG = " + tagFromIntent.toString()); Log.d(TAG, "Writing page " + mSitemapPage + " to tag"); TextView writeTagMessage = findViewById(R.id.write_tag_message); try { URI sitemapURI = new URI(mSitemapPage); if (!sitemapURI.getPath().startsWith("/rest/sitemaps")) { throw new URISyntaxException(mSitemapPage, "Expected a sitemap URL"); } StringBuilder uriToWrite = new StringBuilder("openhab://sitemaps"); uriToWrite.append(sitemapURI.getPath().substring(14)); if (!TextUtils.isEmpty(mItem) && !TextUtils.isEmpty(mCommand)) { uriToWrite.append("?item=").append(mItem).append("&command=").append(mCommand); } writeTagMessage.setText(R.string.info_write_tag_progress); writeTag(tagFromIntent, uriToWrite.toString()); } catch (URISyntaxException e) { Log.e(TAG, e.getMessage()); writeTagMessage.setText(R.string.info_write_failed); } }
From source file:com.sftoolworks.nfcoptions.SelectActivity.java
protected void writeSelection(Intent intent) { ListView list = (ListView) findViewById(R.id.listView1); if (list.getCount() == 0) return;/*from w ww . jav a2 s . c o m*/ try { Object[] results = ((OptionListAdapter) list.getAdapter()).getCheckedValues(); JSONObject obj = new JSONObject(); JSONArray array = new JSONArray(); if (null != results) { for (Object result : results) array.put(result.toString()); } obj.put("selection", array); obj.put("key", selectKey); SharedPreferences sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE); // android studio (0.5.1) decorates this line as an error (some // of the time, anyway) but it's not an error. String identifier = sharedPref.getString(getString(R.string.user_id_key), ""); if (identifier.length() > 0) obj.put("user", identifier); String json = obj.toString(0); String outbound = "\u0002en"; outbound += json; NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, new byte[] { 'T' }, null, outbound.getBytes()); NdefMessage message = new NdefMessage(new NdefRecord[] { textRecord }); Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); Ndef ndef = Ndef.get(tag); ndef.connect(); ndef.writeNdefMessage(message); ndef.close(); Toast.makeText(this, R.string.write_ok, Toast.LENGTH_LONG).show(); new Timer().schedule(new TimerTask() { @Override public void run() { finish(); } }, 1500); } catch (Exception e) { Log.d(TAG, e.toString()); String err = getString(R.string.tag_write_err) + "\n" + e.getMessage(); Toast.makeText(this, err, Toast.LENGTH_LONG).show(); } }
From source file:se.frostyelk.cordova.mifare.MifarePlugin.java
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); NxpLogUtils.i(TAG, "onNewIntent Intent: " + intent.toString()); NxpLogUtils.i(TAG, "onNewIntent Action: " + intent.getAction()); tagInfo = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); // Only act on intents from a tag if (tagInfo == null) { return;//from w ww.j a v a2 s .com } NxpLogUtils.i(TAG, "Tag info: " + tagInfo.toString()); Nxpnfcliblitecallback callback = new Nxpnfcliblitecallback() { @Override public void onNTag210CardDetected(NTag210 nTag210) { NxpLogUtils.i(TAG, "Found a NTag210 Card!"); handleCardDetected(nTag210); } @Override public void onNTag213215216CardDetected(NTag213215216 nTag213215216) { NxpLogUtils.i(TAG, "Found a NTag213215216 Card!"); handleCardDetected(nTag213215216); } @Override public void onNTag213F216FCardDetected(NTag213F216F nTag213F216F) { NxpLogUtils.i(TAG, "Found a NTag213F216F Card!"); handleCardDetected(nTag213F216F); } @Override public void onUltraLightCardDetected(Ultralight ultralight) { handleUnsupportedCards(); } @Override public void onUltraLightCCardDetected(UltralightC ultralightC) { handleUnsupportedCards(); } @Override public void onUltraLightEV1CardDetected(UltralightEV1 ultralightEV1) { handleUnsupportedCards(); } @Override public void onClassicCardDetected(MFClassic mfClassic) { handleUnsupportedCards(); } @Override public void onDESFireCardDetected(DESFire desFire) { handleUnsupportedCards(); } @Override public void onNTag203xCardDetected(NTag203x nTag203x) { handleUnsupportedCards(); } @Override public void onNTagI2CCardDetected(NTagI2C nTagI2C) { handleUnsupportedCards(); } @Override public void onICodeSLIDetected(ICodeSLI iCodeSLI) { handleUnsupportedCards(); } @Override public void onICodeSLISDetected(ICodeSLIS iCodeSLIS) { handleUnsupportedCards(); } @Override public void onICodeSLILDetected(ICodeSLIL iCodeSLIL) { handleUnsupportedCards(); } @Override public void onICodeSLIXDetected(ICodeSLIX iCodeSLIX) { handleUnsupportedCards(); } @Override public void onICodeSLIXSDetected(ICodeSLIXS iCodeSLIXS) { handleUnsupportedCards(); } @Override public void onICodeSLIXLDetected(ICodeSLIXL iCodeSLIXL) { handleUnsupportedCards(); } @Override public void onPlusCardDetected(Plus plus) { handleUnsupportedCards(); } @Override public void onPlusSL1CardDetected(PlusSL1 plusSL1) { handleUnsupportedCards(); } @Override public void onICodeSLIX2Detected(ICodeSLIX2 iCodeSLIX2) { handleUnsupportedCards(); } }; NxpNfcLibLite.getInstance().filterIntent(intent, callback); }
From source file:de.lazyheroproductions.campuscardreader.MainActivity.java
private void startNfcIntentService(Intent intent) { // as far as I can tell is a double check with // NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction()) // unnecessary, but take this as an assumption // if(intent.hasExtra(NfcAdapter.EXTRA_TAG)){ if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Intent newIntent = new Intent(getApplicationContext(), CardReaderIntentService.class); newIntent.putExtra(NfcAdapter.EXTRA_TAG, intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)); startService(newIntent);//from w w w .j a v a 2 s . c o m } }
From source file:de.yazo_games.mensaguthaben.MainActivity.java
@Override public void onNewIntent(Intent intent) { Log.i(TAG, "Foreground dispatch"); if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Log.i(TAG, "Discovered tag with intent: " + intent); Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); try {/*from w w w . j a v a 2 s .c o m*/ ValueData val = Readers.getInstance().readTag(tag); Log.w(TAG, "Setting read data"); valueFragment.setValueData(val); hasNewData = true; } catch (DesfireException e) { Toast.makeText(this, R.string.communication_fail, Toast.LENGTH_SHORT).show(); } } else if (getIntent().getAction().equals(ACTION_FULLSCREEN)) { ValueData valueData = (ValueData) getIntent().getSerializableExtra(EXTRA_VALUE); valueFragment.setValueData(valueData); } }
From source file:org.adictolinux.mfcclone.MainActivity.java
@Override public void onNewIntent(Intent intent) { String action = intent.getAction(); if (scan_fragment != null && NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { Tag tag = (Tag) intent.getExtras().getParcelable(NfcAdapter.EXTRA_TAG); switch (scan_fragment_type) { case 0:/*from w w w. j a v a 2 s . c om*/ ((ForceKeysFragment) scan_fragment).tagFound(tag); break; case 1: ((ImportTagFragment) scan_fragment).tagFound(tag); break; case 2: ((SaveTagDataFragment) scan_fragment).tagFound(tag); break; case 5: ((ResetTagFragment) scan_fragment).tagFound(tag); break; } } }
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;//from www . ja v a 2s . 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:net.networksaremadeofstring.rhybudd.WriteNFCActivity.java
public void onNewIntent(Intent intent) { try {/*from www. j a va 2s .c o m*/ Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); WriteTag(tagFromIntent); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onNewIntent", e); } }
From source file:io.atrac613.AbstractNfcTagFragment.java
/** * ???//from ww w . j a v a 2 s. com * @param intent ????????? */ public void onNewIntent(Intent intent) { String action = intent.getAction(); Log.d(TAG, "incomming intent action = " + action); //TECHDISCOVERED if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action) || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) { mNfcTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); if (mNfcTag != null) { String[] tagTechs = mNfcTag.getTechList(); for (String[] filterTechs : mTechList) { if (ArrayUtil.containArray(tagTechs, filterTechs)) { Log.d(TAG, "** nfcTag = " + mNfcTag.toString()); for (INfcTagListener listener : mListnerList) { //? listener.onTagDiscovered(intent, mNfcTag, this); } } } } } }