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:io.v.android.impl.google.services.beam.BeamActivity.java
@Override public void onResume() { super.onResume(); NdefMessage msgs[] = null;/* w ww. ja v a 2s .co m*/ Intent intent = getIntent(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } } if (msgs == null) { Log.d(TAG, "No ndef messages"); finish(); return; } VBeamManager.Data data = null; for (NdefMessage m : msgs) { data = VBeamManager.decodeMessage(m); if (data != null) break; } if (data == null) { Log.w(TAG, "Unable to deserialize data"); finish(); return; } Log.d(TAG, "connecting to " + data.name); VContext ctx = V.init(this).withTimeout(Duration.standardSeconds(2)); Options opts = new Options(); opts.set(OptionDefs.SERVER_AUTHORIZER, VSecurity.newPublicKeyAuthorizer(data.key)); IntentBeamerClient client = IntentBeamerClientFactory.getIntentBeamerClient(data.name); ListenableFuture<IntentBeamerClient.GetIntentOut> out = client.getIntent(ctx, data.secret, opts); Futures.addCallback(out, new FutureCallback<IntentBeamerClient.GetIntentOut>() { @Override public void onSuccess(IntentBeamerClient.GetIntentOut result) { try { Log.d(TAG, "got intent " + result.intentUri); int flags = 0; if (result.intentUri.startsWith("intent:")) { flags = Intent.URI_INTENT_SCHEME; } else { flags = Intent.URI_ANDROID_APP_SCHEME; } Intent resultIntent = Intent.parseUri(result.intentUri, flags); resultIntent.putExtra(VBeamManager.EXTRA_VBEAM_PAYLOAD, result.payload); startActivity(resultIntent); finish(); } catch (Throwable t) { t.printStackTrace(); } } @Override public void onFailure(Throwable t) { t.printStackTrace(); finish(); } }); }
From source file:net.gpii.android.listener.activity.NfcListenerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nfc);/*from w w w. j a v a 2 s . co m*/ statusTextView = (TextView) findViewById(R.id.nfcStatusText); progressView = (ProgressBar) findViewById(R.id.nfcProgressBar); Button closeButton = (Button) findViewById(R.id.nfcExitButton); closeButton.setOnClickListener(new ActivityQuitListener(this)); try { Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage message = (NdefMessage) messages[0]; NdefRecord record = message.getRecords()[0]; byte[] payload = record.getPayload(); // String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16"; String textEncoding = "UTF-8"; int languageCodeLength = payload[0] & 0077; String username = new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding); if (username.trim().length() == 0) { String errorMessage = "Empty username found on NFC tag."; statusTextView.setText(errorMessage); progressView.setVisibility(View.INVISIBLE); } else { GpiiLoginAsyncTask task = new GpiiLoginAsyncTask(); task.execute(username.trim()); } } catch (UnsupportedEncodingException e) { String errorMessage = "Error unpacking NFC text record."; statusTextView.setText(errorMessage); progressView.setVisibility(View.INVISIBLE); Log.e(Constants.TAG, errorMessage, e); } }
From source file:com.commonsware.android.webbeam.WebBeamActivity.java
private void handleIntent(Intent i) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) { Parcelable[] rawMsgs = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) rawMsgs[0]; String url = new String(msg.getRecords()[0].getPayload()); beamFragment.loadUrl(url);/*from www . ja va 2 s. c om*/ } }
From source file:org.thinkfree.axihome.NFC.TagViewer.java
void resolveIntent(Intent intent) { Log.e(TAG, "Tag detected"); String action = intent.getAction(); Log.e(TAG, action);// w w w . j a v a2s . com if (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 Log.e(TAG, "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 processMessage(msgs); } else { Log.e(TAG, "Unknown intent " + intent); finish(); return; } }
From source file:io.v.example.vbeam.vbeamexample.MainActivity.java
@Override protected void onResume() { super.onResume(); Intent intent = getIntent();//w ww .j a v a2 s . co m if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { for (int i = 0; i < rawMsgs.length; i++) { for (NdefRecord r : ((NdefMessage) rawMsgs[i]).getRecords()) { System.out.println("record " + r.toString() + "(" + r.toUri() + ")"); } } } } }
From source file:org.iotivity.base.examples.SimpleBase.java
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); Log.d(TAG, "onNewIntent with changes sending broadcast IN "); Intent i = new Intent(); i.setAction(intent.getAction());// www . ja v a 2s .c om i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)); sendBroadcast(i); Log.d(TAG, "Initialize Context again resetting"); }
From source file:com.bonsai.wallet32.PairWalletActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mRes = getApplicationContext().getResources(); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_pair_wallet); // Set the state of the reduce false positives checkbox. boolean reduceFalsePositives = mPrefs.getBoolean("pref_reduceBloomFalsePositives", false); CheckBox chkbx = (CheckBox) findViewById(R.id.reduce_false_positives); chkbx.setChecked(reduceFalsePositives); chkbx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*w w w. ja v a2 s.c om*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("pref_reduceBloomFalsePositives", isChecked); editor.commit(); } }); // Hide the reduce bloom false positives if experimental off. Boolean isExperimental = mPrefs.getBoolean(SettingsActivity.KEY_EXPERIMENTAL, false); if (!isExperimental) { findViewById(R.id.reduce_false_positives).setVisibility(View.GONE); findViewById(R.id.reduce_space).setVisibility(View.GONE); } if (savedInstanceState == null) { final Intent intent = this.getIntent(); final String action = intent.getAction(); final String mimeType = intent.getType(); if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && Nfc.MIMETYPE_WALLET32PAIRING.equals(mimeType)) { final NdefMessage ndefMessage = (NdefMessage) intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; final byte[] ndefMessagePayload = Nfc.extractMimePayload(Nfc.MIMETYPE_WALLET32PAIRING, ndefMessage); JSONObject codeObj; try { String msg = new String(ndefMessagePayload, "UTF-8"); codeObj = new JSONObject(msg); } catch (Exception ex) { String msg = "trouble deserializing pairing code: " + ex.toString() + " : " + ndefMessagePayload.toString(); mLogger.error(msg); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); return; } // Setup the wallet in a background task. new PairWalletTask().execute(codeObj); } } }
From source file:net.networksaremadeofstring.rhybudd.PushSettingsFragment.java
void processIntent(Intent intent) { //Log.e("processIntent","processIntent"); try {/*from w w w .j a va2s .co m*/ Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; //Backup our current key prevFilterKey = FilterKey.getText().toString(); // record 0 contains the MIME type, record 1 is the AAR, if present FilterKey.setText(new String(msg.getRecords()[0].getPayload())); /*Message message = Message.obtain(); Bundle bundle = new Bundle(); bundle.putString("newfilterkey",new String(msg.getRecords()[0].getPayload())); message.setData(bundle); message.what = RhybuddHandlers.msg_push_show_undo; checkZPHandler.sendMessageDelayed(message,600);*/ } catch (Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "processIntent", e); } }
From source file:com.battlelancer.seriesguide.ui.AddActivity.java
/** * Parses the NDEF Message from the intent and prints to the TextView *//*from w w w . jav a 2 s.c om*/ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) void processIntent(Intent intent) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; SearchResult show = new SearchResult(); show.tvdbid = Integer.valueOf(new String(msg.getRecords()[0].getPayload())); show.title = new String(msg.getRecords()[1].getPayload()); show.overview = new String(msg.getRecords()[2].getPayload()); // display add dialog AddShowDialogFragment.showAddDialog(show, getSupportFragmentManager()); }
From source file:mai.whack.StickyNotesActivity.java
private void onDataRead(Intent intent) { // Parse the intent NdefMessage[] msgs = null;/*from w w w . j a v a2 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(); }