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;
}
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);
}
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();
}
}
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));
}
}
}
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();
}
}
Aggregations