Search in sources :

Example 1 with NdefRecord

use of android.nfc.NdefRecord in project weiciyuan by qii.

the class MainTimeLineParentActivity method createMimeRecord.

private NdefRecord createMimeRecord(String mimeType, byte[] payload) {
    byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
    NdefRecord mimeRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
    return mimeRecord;
}
Also used : NdefRecord(android.nfc.NdefRecord)

Example 2 with NdefRecord

use of android.nfc.NdefRecord in project weiciyuan by qii.

the class MainTimeLineParentActivity method initNFC.

private void initNFC() {
    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        return;
    }
    mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            String text = (GlobalContext.getInstance().getCurrentAccountName());
            NdefMessage msg = new NdefMessage(new NdefRecord[] { createMimeRecord("application/org.qii.weiciyuan.beam", text.getBytes()), NdefRecord.createApplicationRecord(getPackageName()) });
            return msg;
        }
    }, this);
}
Also used : NdefRecord(android.nfc.NdefRecord) NfcEvent(android.nfc.NfcEvent) NdefMessage(android.nfc.NdefMessage) NfcAdapter(android.nfc.NfcAdapter)

Example 3 with NdefRecord

use of android.nfc.NdefRecord in project cw-advandroid 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(intent.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 4 with NdefRecord

use of android.nfc.NdefRecord 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 5 with NdefRecord

use of android.nfc.NdefRecord 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)

Aggregations

NdefRecord (android.nfc.NdefRecord)12 NdefMessage (android.nfc.NdefMessage)9 NfcAdapter (android.nfc.NfcAdapter)3 NfcEvent (android.nfc.NfcEvent)2 Tag (android.nfc.Tag)2 Parcelable (android.os.Parcelable)2 Intent (android.content.Intent)1 FormatException (android.nfc.FormatException)1 Ndef (android.nfc.tech.Ndef)1 IOException (java.io.IOException)1