List of usage examples for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES
String EXTRA_NDEF_MESSAGES
To view the source code for android.nfc NfcAdapter EXTRA_NDEF_MESSAGES.
Click Source Link
This extra is mandatory for #ACTION_NDEF_DISCOVERED intents, and optional for #ACTION_TECH_DISCOVERED , and #ACTION_TAG_DISCOVERED intents.
When this extra is present there will always be at least one NdefMessage element.
From source file:com.evandroid.musica.MainLyricActivity.java
@TargetApi(14) private Lyrics getBeamedLyrics(Intent intent) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam if (rawMsgs != null && rawMsgs.length > 0) { NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present NdefRecord[] records = msg.getRecords(); if (records.length > 0) { try { return Lyrics.fromBytes(records[0].getPayload()); } catch (IOException | ClassNotFoundException e) { e.printStackTrace();/* ww w. ja v a 2 s . c o m*/ } } } return null; }
From source file:com.github.vgoliveira.panificadora.MainActivity.java
private void nfc_init() { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { NdefMessage[] msgs = null;/*from w ww .java 2 s . c o m*/ Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); String deviceAddress; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; ++i) { msgs[i] = (NdefMessage) rawMsgs[i]; } NdefRecord[] records = msgs[0].getRecords(); deviceAddress = new String(records[1].getPayload(), 1, records[1].getPayload().length - 1, Charset.forName("UTF-8")); // record 1 contains the MAC Address deviceAddress = deviceAddress.substring(2); // remove the language mark "en" coded in the NDEF text/plain record mDevice = mBtAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); // no testa s retorna mDevice com o endereo passado ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); Log.d(TAG, "... NFC_init mDevice= " + mDevice + " mService= " + mService); } } }
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
void resolveIntent(Intent intent) { // Parse the intent String action = intent.getAction(); Log.d("TAG_VIEWER", "in resolve intent"); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { // When a tag is discovered we send it to the service to // be save. We // include a PendingIntent for the service to call back // onto. This // will cause this activity to be restarted with // onNewIntent(). At // that time we read it from the database and view it. Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs;//from w w w . jav a 2 s . co m 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 }; } // Setup the views setTitle(R.string.title_scanned_tag); buildTagViews(msgs); } else { Log.e(TAG, "Unknown intent " + intent); // finish(); return; } }
From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java
private void handleIntent(Intent intent) { String id = null;/*ww w.ja v a 2 s . co m*/ if (intent != null) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present id = new String(msg.getRecords()[0].getPayload()); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID)); } if (StringUtils.contains(id, "europeana.eu/")) { Uri uri = Uri.parse(id); List<String> paths = uri.getPathSegments(); if ((paths != null) && (paths.size() == 4)) { String collectionId = paths.get(paths.size() - 2); String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html"); id = StringUtils.join("/", collectionId, "/", recordId); } else { // invalid url/id, cancel opening record id = null; } } if (StringUtils.isNotBlank(id)) { openRecord(id); } } }
From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java
private void handleIntent(Intent intent) { String query = null;/* ww w. j a v a2 s.c o m*/ String[] qf = null; if (intent != null) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY)); } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) parcelables[0]; Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload())); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { query = intent.getDataString(); if (!TextUtils.isEmpty(query)) { if (StringUtils.contains(query, "europeana.eu/")) { Uri uri = Uri.parse(query); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } } } else { // no search action recognized? end this activity... closeSearchActivity(); } if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) { runningSearch = query; if (StringArrayUtils.isNotBlank(qf)) { searchController.newSearch(this, query, qf); } else { searchController.newSearch(this, query); } getSupportActionBar().setTitle(searchController.getSearchTitle(this)); } } }
From source file:pl.edu.pw.eiti.groupbuying.partner.android.ClaimCouponsActivity.java
/** * Parses the NDEF Message from the intent and prints to the TextView *//*from www .jav a2s . c o m*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1) private void processIntent(Intent intent) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present extractCouponInfo(new String(msg.getRecords()[0].getPayload())); setIntent(null); }
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * On create, process NDEF message with its intent action * //from ww w .j a v a2s .c om * @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; }
From source file:com.rimbit.android_wallet.ui.SendCoinsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/*w w w . j a va 2 s .c om*/ setHasOptionsMenu(true); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); if (savedInstanceState != null) { restoreInstanceState(savedInstanceState); } else { final Intent intent = activity.getIntent(); final String action = intent.getAction(); final Uri intentUri = intent.getData(); final String scheme = intentUri != null ? intentUri.getScheme() : null; final String mimeType = intent.getType(); if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && intentUri != null && "rimbit".equals(scheme)) { initStateFromRimbitUri(intentUri); } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) { final NdefMessage ndefMessage = (NdefMessage) intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST, ndefMessage); initStateFromPaymentRequest(mimeType, ndefMessagePayload); } else if ((Intent.ACTION_VIEW.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) { final byte[] paymentRequest = RimbitIntegration.paymentRequestFromIntent(intent); if (intentUri != null) initStateFromIntentUri(mimeType, intentUri); else if (paymentRequest != null) initStateFromPaymentRequest(mimeType, paymentRequest); else throw new IllegalArgumentException(); } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) { initStateFromIntentExtras(intent.getExtras()); } else { updateStateFrom(PaymentIntent.blank()); } } }
From source file:de.langerhans.wallet.ui.SendCoinsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);//from ww w.j a v a2 s .co m setHasOptionsMenu(true); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); if (savedInstanceState != null) { restoreInstanceState(savedInstanceState); } else { final Intent intent = activity.getIntent(); final String action = intent.getAction(); final Uri intentUri = intent.getData(); final String scheme = intentUri != null ? intentUri.getScheme() : null; final String mimeType = intent.getType(); if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && intentUri != null && "dogecoin".equals(scheme)) { initStateFromBitcoinUri(intentUri); } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && com.google.dogecoin.protocols.payments.PaymentProtocol.MIMETYPE_PAYMENTREQUEST .equals(mimeType)) { final NdefMessage ndefMessage = (NdefMessage) intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; final byte[] ndefMessagePayload = Nfc.extractMimePayload( com.google.dogecoin.protocols.payments.PaymentProtocol.MIMETYPE_PAYMENTREQUEST, ndefMessage); initStateFromPaymentRequest(mimeType, ndefMessagePayload); } else if ((Intent.ACTION_VIEW.equals(action)) && com.google.dogecoin.protocols.payments.PaymentProtocol.MIMETYPE_PAYMENTREQUEST .equals(mimeType)) { final byte[] paymentRequest = BitcoinIntegration.paymentRequestFromIntent(intent); if (intentUri != null) initStateFromIntentUri(mimeType, intentUri); else if (paymentRequest != null) initStateFromPaymentRequest(mimeType, paymentRequest); else throw new IllegalArgumentException(); } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) { initStateFromIntentExtras(intent.getExtras()); } else { updateStateFrom(PaymentIntent.blank()); } } }
From source file:com.bushstar.kobocoin_android_wallet.ui.SendCoinsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/*from w w w . ja v a 2 s .c om*/ setHasOptionsMenu(true); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); if (savedInstanceState != null) { restoreInstanceState(savedInstanceState); } else { final Intent intent = activity.getIntent(); final String action = intent.getAction(); final Uri intentUri = intent.getData(); final String scheme = intentUri != null ? intentUri.getScheme() : null; final String mimeType = intent.getType(); if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && intentUri != null && "kobocoin".equals(scheme)) { initStateFromKobocoinUri(intentUri); } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) { final NdefMessage ndefMessage = (NdefMessage) intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST, ndefMessage); initStateFromPaymentRequest(mimeType, ndefMessagePayload); } else if ((Intent.ACTION_VIEW.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) { final byte[] paymentRequest = KobocoinIntegration.paymentRequestFromIntent(intent); if (intentUri != null) initStateFromIntentUri(mimeType, intentUri); else if (paymentRequest != null) initStateFromPaymentRequest(mimeType, paymentRequest); else throw new IllegalArgumentException(); } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) { initStateFromIntentExtras(intent.getExtras()); } else { updateStateFrom(PaymentIntent.blank()); } } }