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:com.nfc.gemkey.MainActivity.java
@Override public void onNewIntent(Intent intent) { if (DEBUG)/*from w ww . jav a2 s . com*/ Log.d(TAG, "onNewIntent"); final String action = intent.getAction(); if (action.equals(NfcAdapter.ACTION_TAG_DISCOVERED)) { if (DEBUG) Log.i(TAG, "Discovered tag with intent: " + action); Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String nfc_tag_id = bytesToHexString(myTag.getId()).toUpperCase(); tagId.setText("Tag ID : " + nfc_tag_id); if (mCheckTagInfoThread != null && mCheckTagInfoThread.isAlive()) { mCheckTagInfoThread.terminate(); mCheckTagInfoThread = null; } mCheckTagInfoThread = new CheckTagInfoThread(nfc_tag_id); mCheckTagInfoThread.start(); } }
From source file:com.hybris.mobile.activity.AbstractProductDetailActivity.java
/** * Handle incoming intents. Do not load a product if we already have one. *///from w w w . j av a2s . co m @Override protected void onResume() { super.onResume(); String[] options = { InternalConstants.PRODUCT_OPTION_BASIC, InternalConstants.PRODUCT_OPTION_CATEGORIES, InternalConstants.PRODUCT_OPTION_CLASSIFICATION, InternalConstants.PRODUCT_OPTION_DESCRIPTION, InternalConstants.PRODUCT_OPTION_GALLERY, InternalConstants.PRODUCT_OPTION_PRICE, InternalConstants.PRODUCT_OPTION_PROMOTIONS, InternalConstants.PRODUCT_OPTION_REVIEW, InternalConstants.PRODUCT_OPTION_STOCK, InternalConstants.PRODUCT_OPTION_VARIANT }; String productCode = null; Intent intent = getIntent(); // Direct Call if (intent.hasExtra(DataConstants.PRODUCT_CODE)) //direct call from search list for example { productCode = intent.getStringExtra(DataConstants.PRODUCT_CODE); } // NFC Call else if (intent.hasExtra(NfcAdapter.EXTRA_TAG)) //NFC { Tag tag = getIntent().getExtras().getParcelable(NfcAdapter.EXTRA_TAG); Ndef ndef = Ndef.get(tag); NdefMessage message = ndef.getCachedNdefMessage(); NdefRecord record = message.getRecords()[0]; if (record.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(record.getType(), NdefRecord.RTD_URI)) { productCode = RegexUtil .getProductCode(new String(record.getPayload(), 1, record.getPayload().length - 1)); } } // Call from another application (QR Code) else if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) { productCode = RegexUtil.getProductCode(intent.getDataString()); } if (StringUtils.isNotEmpty(productCode)) { this.enableAndroidBeam(productCode); } // Only load if we don't have a product already if (mProduct == null) { populateProduct(productCode, options); } invalidateOptionsMenu(); }
From source file:st.alr.homA.ActivityQuickpublishNfc.java
@Override protected void onNewIntent(Intent intent) { Log.v(this.toString(), "write mode: " + writeMode); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) && writeMode == true) { Tag mytag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); Log.v(this.toString(), "Detected tag: " + mytag.toString()); Log.v(this.toString(), "techlist:" + mytag.getTechList()); ArrayList<Quickpublish> qps = adapter.getValues(); if (qps.size() < 1) { publishProgress(getResources().getString(R.string.nfcWriteDialogTagNoContent), false); return; }/*from w ww . j av a 2 s . c om*/ if (write(Quickpublish.toJsonString(qps), mytag)) { Log.v(this.toString(), "Write ok"); publishProgress(getResources().getString(R.string.nfcWriteDialogTagSuccess), true); } else { Log.e(this.toString(), "Write fail"); } } }
From source file:net.tjohns.badgescanner.ScanActivity.java
private void scanBadge() { Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATION_DURATION); Intent intent = getIntent();/* www . ja v a 2 s. c om*/ if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) { Tag rawTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); MifareClassic tag = MifareClassic.get(rawTag); try { // Read from badge NfcConnection tagConnection = new NfcConnection(tag, MifareClassic.KEY_DEFAULT); mBadge = new Badge(); mBadge.readFromTag(tagConnection); tagConnection.close(); } catch (TagLostException e) { // TODO(trevorjohns): Convert to dialog Toast.makeText(this, "Tag lost", Toast.LENGTH_LONG); finish(); } catch (IOException e) { // TODO(trevorjohns): Convert to dialog Toast.makeText(this, "IOExcpetion detected", Toast.LENGTH_LONG); e.printStackTrace(); finish(); } } }
From source file:org.sufficientlysecure.keychain.ui.PassphraseWizardActivity.java
@Override protected void onNewIntent(Intent intent) { if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { myTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); if (writeNFC && CREATE_METHOD.equals(selectedAction)) { //write new password on NFC tag try { if (myTag != null) { write(myTag);/*from w ww .ja v a2s. c o m*/ writeNFC = false; //just write once Toast.makeText(this, R.string.nfc_write_succesful, Toast.LENGTH_SHORT).show(); //advance to lockpattern // LockPatternFragmentOld lpf = LockPatternFragmentOld.newInstance(selectedAction); // FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // transaction.replace(R.id.fragmentContainer, lpf).addToBackStack(null).commit(); } } catch (IOException | FormatException e) { Log.e(Constants.TAG, "Failed to write on NFC tag", e); } } else if (readNFC && AUTHENTICATION.equals(selectedAction)) { //read pw from NFC tag try { if (myTag != null) { //if tag detected, read tag String pwtag = read(myTag); if (output != null && pwtag.equals(output.toString())) { //passwort matches, go to next view Toast.makeText(this, R.string.passphrases_match + "!", Toast.LENGTH_SHORT).show(); // LockPatternFragmentOld lpf = LockPatternFragmentOld.newInstance(selectedAction); // FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // transaction.replace(R.id.fragmentContainer, lpf).addToBackStack(null).commit(); readNFC = false; //just once } else { //passwort doesnt match TextView nfc = (TextView) findViewById(R.id.nfcText); nfc.setText(R.string.nfc_wrong_tag); } } } catch (IOException | FormatException e) { Log.e(Constants.TAG, "Failed to read NFC tag", e); } } } }
From source file:com.tananaev.passportreader.MainActivity.java
@Override public void onNewIntent(Intent intent) { if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Tag tag = intent.getExtras().getParcelable(NfcAdapter.EXTRA_TAG); if (Arrays.asList(tag.getTechList()).contains("android.nfc.tech.IsoDep")) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String passportNumber = preferences.getString(KEY_PASSPORT_NUMBER, null); String expirationDate = convertDate(preferences.getString(KEY_EXPIRATION_DATE, null)); String birthDate = convertDate(preferences.getString(KEY_BIRTH_DATE, null)); if (passportNumber != null && !passportNumber.isEmpty() && expirationDate != null && !expirationDate.isEmpty() && birthDate != null && !birthDate.isEmpty()) { BACKeySpec bacKey = new BACKey(passportNumber, birthDate, expirationDate); new ReadTask(IsoDep.get(tag), bacKey).execute(); mainLayout.setVisibility(View.GONE); loadingLayout.setVisibility(View.VISIBLE); } else { Snackbar.make(passportNumberView, R.string.error_input, Snackbar.LENGTH_SHORT).show(); }//from w w w. j a va 2s . c o m } } }
From source file:org.irmacard.androidmanagement.CredentialListActivity.java
public void processIntent(Intent intent) { tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); IsoDep isotag = IsoDep.get(tag);/*w w w. j a v a 2s. c o m*/ if (isotag != null) { // We are waiting for the card, notify dialog if (currentState == State.WAITING_FOR_CARD) { cardMissingDialog.dismiss(); gotoState(State.TEST_CARD_PRESENCE); } } }
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.tag_viewer); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); Intent intent = this.getIntent(); writeContent = intent.getStringExtra("writeContent"); mLoginButton = new LoginButton(getApplicationContext()); // if(flag == true) Log.d("TAG_VIEWER", "writeConent:" + writeContent); // setContentView(R.layout.tag_viewer); mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // mTagContent = (LinearLayout) findViewById(R.id.list); // mTitle = (TextView) findViewById(R.id.title); Log.d("TAG_VIEWER", "Utility.mFacebook is " + Utility.mFacebook); if (Utility.mFacebook == null) { InitializeLogin = true;/* w ww . ja v a 2s .c o m*/ } // Create the Facebook Object using the app id. edu.cmu.mpcs.dashboard.Utility.mFacebook = new Facebook(APP_ID); // Instantiate the asynrunner object for asynchronous api calls. edu.cmu.mpcs.dashboard.Utility.mAsyncRunner = new AsyncFacebookRunner( edu.cmu.mpcs.dashboard.Utility.mFacebook); Log.d("TAG_VIEWER", "in oncreate in TagViewer is session valid?:" + Utility.mFacebook.isSessionValid()); mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see FbAPIs.java"); return; } SessionStore.restore(Utility.mFacebook, this); SessionEvents.addAuthListener(new FbAPIsAuthListener()); SessionEvents.addLogoutListener(new FbAPIsLogoutListener()); // SessionEvents.r if (Utility.mFacebook.isSessionValid()) { requestUserData(); } // TODO do something about - dont call resolve intent by // default. if (writeContent == null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Log.d("TAG_VIEWER", "in OnCreate Before reading"); loginIntent = intent; if (InitializeLogin) { /* * This is if we come to tag viewer without * having started dashboard activity */ mLoginButton.initializeFbLogin(); } else { /* This is we if read the tag while in dashboard! */ resolveIntent(intent); } // mLoginButton.performLogout(); } else { Log.d("TAG_VIEWER", "Before creating alert dialog"); builder = new AlertDialog.Builder(TagViewer.this); dialog = builder.create(); builder.setTitle("Touch tag to write").setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { Log.d("TAG_VIEWER", "On cancel called"); disableTagWriteMode(); } }).create(); dialog.setTitle("touch tag to write"); dialog.show(); dialog.setOnDismissListener(new OnDismissListener() { public void onDismiss(DialogInterface dialog) { // TODO Auto-generated method stub Log.d("TAG_VIEWER", "On dismiss called"); disableTagWriteMode(); } }); // builder.setCancelable(true); // builder.setOnCancelListener(new // DialogInterface.OnCancelListener() { // public void onCancel(DialogInterface dialog) { // Log.d("TAG_VIEWER","On cancel called"); // disableTagWriteMode(); // // } // }).create().show(); } // Tag writing mode if (writeContent != null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Log.d("TAG_VIEWER", "in Oncreate Before writing"); Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); try { WriteToTag.write(detectedTag, writeContent); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("TAG_VIEWER", "in on create, writing to tag"); } Log.d("TAG_VIEWER", "in create"); }
From source file:com.shanet.relayremote.Main.java
public void onNewIntent(Intent intent) { // When an NFC tag is being written, call the write tag function when an intent is // received that says the tag is within range of the device and ready to be written to Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String nfcMessage = intent.getStringExtra("nfcMessage"); if (nfcMessage != null) { NFC.writeTag(this, tag, nfcMessage); }//from w w w . ja v a 2 s . c om }