Search in sources :

Example 6 with NdefRecord

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

Example 7 with NdefRecord

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

Example 8 with NdefRecord

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

Example 9 with NdefRecord

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

Example 10 with NdefRecord

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

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