Search in sources :

Example 1 with NdefMessage

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());
}
Also used : NdefMessage(android.nfc.NdefMessage) Parcelable(android.os.Parcelable)

Example 2 with NdefMessage

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));
        }
    }
}
Also used : NdefRecord(android.nfc.NdefRecord) NdefMessage(android.nfc.NdefMessage) Parcelable(android.os.Parcelable)

Example 3 with NdefMessage

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();
}
Also used : NdefMessage(android.nfc.NdefMessage) Tag(android.nfc.Tag)

Example 4 with NdefMessage

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();
    }
}
Also used : NdefRecord(android.nfc.NdefRecord) NdefMessage(android.nfc.NdefMessage) Tag(android.nfc.Tag)

Example 5 with NdefMessage

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);
    }
}
Also used : NdefMessage(android.nfc.NdefMessage) Parcelable(android.os.Parcelable)

Aggregations

NdefMessage (android.nfc.NdefMessage)39 NdefRecord (android.nfc.NdefRecord)23 IOException (java.io.IOException)17 FormatException (android.nfc.FormatException)10 Ndef (android.nfc.tech.Ndef)10 Parcelable (android.os.Parcelable)9 INfcTag (android.nfc.INfcTag)7 TagLostException (android.nfc.TagLostException)7 RemoteException (android.os.RemoteException)7 NfcAdapter (android.nfc.NfcAdapter)6 Intent (android.content.Intent)4 NfcEvent (android.nfc.NfcEvent)4 Tag (android.nfc.Tag)4 SuppressLint (android.annotation.SuppressLint)2 Uri (android.net.Uri)2 NdefFormatable (android.nfc.tech.NdefFormatable)2 Bundle (android.os.Bundle)2 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)2 Activity (android.app.Activity)1 ContentResolver (android.content.ContentResolver)1