use of android.nfc.NdefMessage in project SeriesGuide by UweTrottmann.
the class SearchActivity method handleBeamIntent.
/**
* Extracts the beamed show from the NDEF Message and displays an add dialog for the show.
*/
private void handleBeamIntent(Intent intent) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (rawMsgs == null || rawMsgs.length == 0) {
// corrupted or invalid data
return;
}
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
int showTvdbId;
try {
showTvdbId = Integer.valueOf(new String(msg.getRecords()[0].getPayload()));
} catch (NumberFormatException e) {
return;
}
// display add dialog
AddShowDialogFragment.showAddDialog(showTvdbId, getSupportFragmentManager());
}
use of android.nfc.NdefMessage in project cw-omnibus by commonsguy.
the class MainActivity method readFromTag.
void readFromTag(Intent i) {
Parcelable[] msgs = (Parcelable[]) i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (msgs.length > 0) {
NdefMessage msg = (NdefMessage) msgs[0];
if (msg.getRecords().length > 0) {
NdefRecord rec = msg.getRecords()[0];
secretMessage.setText(new String(rec.getPayload(), US_ASCII));
}
}
}
use of android.nfc.NdefMessage in project cw-omnibus by commonsguy.
the class MainActivity method writeToTag.
void writeToTag(Intent i) {
Tag tag = i.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefMessage msg = new NdefMessage(new NdefRecord[] { buildNdefRecord() });
new WriteTagTask(this, msg, tag).execute();
}
use of android.nfc.NdefMessage in project cw-omnibus by commonsguy.
the class URLTagger method onNewIntent.
@Override
protected void onNewIntent(Intent intent) {
if (inWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] url = buildUrlBytes(getIntent().getStringExtra(Intent.EXTRA_TEXT));
NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[] {}, url);
NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
new WriteTask(this, msg, tag).execute();
}
}
use of android.nfc.NdefMessage in project cw-omnibus by commonsguy.
the class WebBeamActivity method handleIntent.
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);
}
}
Aggregations