use of android.nfc.NdefRecord in project cw-omnibus by commonsguy.
the class WebBeamActivity method createNdefMessage.
@Override
public NdefMessage createNdefMessage(NfcEvent arg0) {
NdefRecord uriRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, MIME_TYPE.getBytes(Charset.forName("US-ASCII")), new byte[0], beamFragment.getUrl().getBytes(Charset.forName("US-ASCII")));
NdefMessage msg = new NdefMessage(new NdefRecord[] { uriRecord, NdefRecord.createApplicationRecord("com.commonsware.android.webbeam") });
return (msg);
}
use of android.nfc.NdefRecord in project bitcoin-wallet by bitcoin-wallet.
the class Nfc method createMime.
public static NdefRecord createMime(final String mimeType, final byte[] payload) {
final byte[] mimeBytes = mimeType.getBytes(StandardCharsets.US_ASCII);
final NdefRecord mimeRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
return mimeRecord;
}
use of android.nfc.NdefRecord in project iosched by google.
the class BeamUtils method tryUpdateIntentFromBeam.
/**
* Checks to see if the activity's intent ({@link android.app.Activity#getIntent()}) is
* an NFC intent that the app recognizes. If it is, then parse the NFC message and set the
* activity's intent (using {@link Activity#setIntent(android.content.Intent)}) to something
* the app can recognize (i.e. a normal {@link Intent#ACTION_VIEW} intent).
*/
public static void tryUpdateIntentFromBeam(Activity activity) {
Intent originalIntent = activity.getIntent();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(originalIntent.getAction())) {
Parcelable[] rawMsgs = originalIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage msg = (NdefMessage) rawMsgs[0];
// Record 0 contains the MIME type, record 1 is the AAR, if present.
// In iosched, AARs are not present.
NdefRecord mimeRecord = msg.getRecords()[0];
if (ScheduleContract.makeContentItemType(ScheduleContract.Sessions.CONTENT_TYPE_ID).equals(new String(mimeRecord.getType()))) {
// Re-set the activity's intent to one that represents session details.
Intent sessionDetailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(new String(mimeRecord.getPayload())));
activity.setIntent(sessionDetailIntent);
}
}
}
use of android.nfc.NdefRecord in project iosched by google.
the class BeamUtils method setBeamSessionUri.
/**
* Sets this activity's Android Beam message to one representing the given session.
*/
public static void setBeamSessionUri(Activity activity, Uri sessionUri) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter == null) {
// No NFC :-(
return;
}
nfcAdapter.setNdefPushMessage(new NdefMessage(new NdefRecord[] { new NdefRecord(NdefRecord.TNF_MIME_MEDIA, ScheduleContract.makeContentItemType(ScheduleContract.Sessions.CONTENT_TYPE_ID).getBytes(), new byte[0], sessionUri.toString().getBytes()) }), activity);
}
use of android.nfc.NdefRecord in project weiciyuan by qii.
the class AbstractAppActivity 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;
}
Aggregations