NdefRecord buildNdefRecord() { return(new NdefRecord(NdefRecord.TNF_MIME_MEDIA, MIME_TYPE.getBytes(), new byte[] {}, secretMessage.getText().toString().getBytes())); }
@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); } }
@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(); } }
@Test public void setNdefPushMessage_setsNonNullMessage() throws Exception { final Activity activity = Robolectric.setupActivity(Activity.class); final NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity); final NdefMessage message = new NdefMessage(new NdefRecord[] {new NdefRecord(NdefRecord.TNF_EMPTY, null, null, null)}); adapter.setNdefPushMessage(message, activity); assertThat(shadowOf(adapter).getNdefPushMessage()).isSameAs(message); }
@Override public NdefRecord getNdefRecord() { return new NdefRecord(NdefRecord.TNF_UNKNOWN, EMPTY, id != null ? id : EMPTY, payload != null ? payload : EMPTY); } }
@Override public NdefRecord getNdefRecord() { return new NdefRecord(NdefRecord.TNF_EMPTY, EMPTY, id != null ? id : EMPTY, EMPTY); } }
@Override public NdefRecord getNdefRecord() { byte[] payload = new byte[] { (byte)((randomNumber >> 8) & 0xFF), (byte)(randomNumber & 0xFF) }; // msb, lsb return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, type, id != null ? id : EMPTY, payload); }
@Override public NdefRecord getNdefRecord() { return new NdefRecord(tnf, type != null ? type : EMPTY, id != null ? id : EMPTY, payload != null ? payload : EMPTY); }
@Override public NdefRecord getNdefRecord() { if(!hasUri()) { throw new IllegalArgumentException("Expected URI"); } return new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, AbsoluteUriRecord.TYPE, id != null ? id : EMPTY, uri.getBytes(Charset.forName("US-ASCII"))); } }
public static final NdefMessage getEmptyNdef() { byte[] empty = new byte[] {}; NdefRecord[] records = new NdefRecord[1]; records[0] = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, empty, empty, empty); NdefMessage ndef = new NdefMessage(records); return ndef; }
public static NdefMessage fromMime(String mimeType, byte[] data) { try { NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(), new byte[0], data); NdefRecord[] records = new NdefRecord[] { record }; return new NdefMessage(records); } catch (NoClassDefFoundError e) { return null; } }
@Override public NdefRecord getNdefRecord() { if(!hasMimeType()) { throw new IllegalArgumentException("Expected content type"); } // the android api normalizes the content type, I dont see why you would want that return new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(Charset.forName("US-ASCII")), id != null ? id : EMPTY, data != null ? data : EMPTY); }
private NdefMessage createMessage(String payload) { String mimeType = "application/com.professionalandroid.apps.nfcbeam"; byte[] tagId = new byte[0]; NdefMessage nfcMessage = new NdefMessage(new NdefRecord[] { // Create the NFC payload. new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(Charset.forName("US-ASCII")), tagId, payload.getBytes(Charset.forName("US-ASCII"))), // Add the AAR (Android Application Record) NdefRecord.createApplicationRecord("com.professionalandroid.apps.nfcbeam") }); return nfcMessage; }
@Deprecated private NdefRecord createExternal(String domain, String type, byte[] data) { if (domain == null) throw new NullPointerException("domain is null"); if (type == null) throw new NullPointerException("type is null"); domain = domain.trim().toLowerCase(Locale.US); type = type.trim().toLowerCase(Locale.US); if (domain.length() == 0) throw new IllegalArgumentException("domain is empty"); if (type.length() == 0) throw new IllegalArgumentException("type is empty"); byte[] byteDomain = domain.getBytes(Charset.forName("UTF-8")); byte[] byteType = type.getBytes(Charset.forName("UTF-8")); byte[] b = new byte[byteDomain.length + 1 + byteType.length]; System.arraycopy(byteDomain, 0, b, 0, byteDomain.length); b[byteDomain.length] = ':'; System.arraycopy(byteType, 0, b, byteDomain.length + 1, byteType.length); // external type id must be empty return new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, b, EMPTY, data != null ? data : EMPTY); }
@Override public NdefRecord getNdefRecord() { if (!hasTargetIdentifier()) { throw new IllegalArgumentException("Expected target identifier"); } return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, type, id != null ? id : EMPTY, targetIdentifier.toByteArray()); } }
@Override public NdefRecord getNdefRecord() { if (!hasAction()) { throw new IllegalArgumentException("Expected action"); } return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, type, id != null ? id : EMPTY, new byte[] {action.getValue()}); }
@Override public NdefRecord getNdefRecord() { NdefRecord[] ndefRecords = new NdefRecord[records.size()]; for(int i = 0; i < records.size(); i++) { ndefRecords[i] = records.get(i).getNdefRecord(); } return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, type, id != null ? id : EMPTY, new NdefMessage(ndefRecords).toByteArray()); } }
/** * Generate an NDEF message containing the given Wi-Fi configuration * * @param wifiNetwork the Wi-Fi configuration to convert * @return an NDEF message containing the given Wi-Fi configuration */ public static NdefMessage generateNdefMessage(WifiNetwork wifiNetwork) { byte[] payload = generateNdefPayload(wifiNetwork); NdefRecord mimeRecord = new NdefRecord( NdefRecord.TNF_MIME_MEDIA, NfcUtils.NFC_TOKEN_MIME_TYPE.getBytes(Charset.forName("US-ASCII")), new byte[0], payload); NdefRecord aarRecord = NdefRecord.createApplicationRecord(PACKAGE_NAME); return new NdefMessage(new NdefRecord[] {mimeRecord, aarRecord}); }
@Override public NdefRecord getNdefRecord() { byte[] payload = null; if (hasAction() && hasActionRecord()) { throw new IllegalArgumentException("Expected action or action record, not both."); } if (hasAction()) { payload = new byte[2]; payload[0] = GcActionRecord.NUMERIC_CODE; payload[1] = (byte)action.getValue(); } else if (hasActionRecord()) { byte[] subPayload = actionRecord.toByteArray(); payload = new byte[subPayload.length + 1]; payload[0] = 0; System.arraycopy(subPayload, 0, payload, 1, subPayload.length); } else { throw new IllegalArgumentException("Expected action or action record."); } return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, type, id != null ? id : EMPTY, payload); }
@Override public NdefRecord getNdefRecord() { Message message = new Message(); if (hasTitle()) { message.add(title); } if (hasUri()) { message.add(uri); } if (hasAction()) { message.add(action); } return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_SMART_POSTER, id != null ? id : EMPTY, message.getNdefMessage().toByteArray()); } }