List of usage examples for android.nfc NdefMessage NdefMessage
public NdefMessage(NdefRecord[] records)
From source file:Main.java
public static NdefMessage ndefMessageForVcard(String paramString1, String paramString2) { NdefRecord[] arrayOfNdefRecord = new NdefRecord[1]; arrayOfNdefRecord[0] = createVcard(getContactContents(paramString1, paramString2)); return new NdefMessage(arrayOfNdefRecord); }
From source file:Main.java
public static NdefMessage createNdefVCard(String vcard) { NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, MIME_TYPE_VCARD.getBytes(), new byte[] {}, vcard.getBytes());/*w w w .j av a 2s . c o m*/ return new NdefMessage(new NdefRecord[] { record }); }
From source file:Main.java
public static void enableNFCWriteMode(Activity activity, NfcAdapter nfcAdapter, String textToWrite) { NdefRecord textRecord = createTextRecord(textToWrite, true); NdefMessage msg = new NdefMessage(new NdefRecord[] { textRecord }); nfcAdapter.enableForegroundNdefPush(activity, msg); }
From source file:Main.java
public static NdefMessage ndefMessageForText(String paramString1, String paramString2) { NdefRecord[] arrayOfNdefRecord = new NdefRecord[1]; arrayOfNdefRecord[0] = createText(paramString1, paramString2); return new NdefMessage(arrayOfNdefRecord); }
From source file:Main.java
@TargetApi(14) public static boolean setPushMessage(Activity activity, Uri toShare) { NfcAdapter adapter = getAdapter(activity); if (adapter != null) { adapter.setNdefPushMessage(new NdefMessage(new NdefRecord[] { NdefRecord.createUri(toShare), }), activity);/*from w w w . j a v a 2s .c om*/ return true; } return false; }
From source file:Main.java
public static NdefMessage[] getNdefMessages(Parcelable[] rawMsgs) { // Parse the intent NdefMessage[] msgs = null;// w ww .j a v a 2 s. c om if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } return msgs; }
From source file:Main.java
/** * Write the current IP address of the Android device to an NFC Tag. Must be connected to wifi network. * * @param tag NFC Tag to write message to * @param wifi WifiManager which can be used to retrieve IP address * @throws IOException// w w w . j ava 2 s. c o m * @throws FormatException * @throws IllegalStateException when Android device is not connected to Wifi network */ public static void writeIpAddress(Tag tag, WifiManager wifi) throws IOException, FormatException, IllegalStateException { String ipAddress = getIpAddr(wifi); if (ipAddress.equals("0.0.0.0")) { throw new IllegalStateException("Not connected to Wifi"); } NdefRecord[] records = { createRecord(ipAddress) }; NdefMessage message = new NdefMessage(records); Ndef ndef = Ndef.get(tag); ndef.connect(); ndef.writeNdefMessage(message); ndef.close(); }
From source file:de.stadtrallye.rallyesoft.net.NfcCallback.java
@Override @TargetApi(14)/* ww w .ja v a2s.c om*/ public NdefMessage createNdefMessage(NfcEvent event) { ObjectMapper mapper = Serialization.getJsonInstance(); String text = null; try { text = mapper.writeValueAsString(server.exportLogin()); } catch (JsonProcessingException e) { Log.e(THIS, "Could not export Login", e); } NdefMessage msg = new NdefMessage(new NdefRecord[] { new NdefRecord(NdefRecord.TNF_MIME_MEDIA, Std.APP_MIME.getBytes(Charset.forName("US-ASCII")), new byte[0], text.getBytes(Charset.forName("US_ASCII"))), NdefRecord.createApplicationRecord("de.stadtrallye.rallyesoft") }); return msg; }
From source file:root.gast.playground.speech.activation.util.TagWriterExecutionActivity.java
/** * create a new NDEF record and containing NDEF message using the app's * custom MIME type but that is otherwise empty. * /*from w ww . j a v a2 s . co m*/ * @return */ private NdefMessage createMimeTypeMessage() { String mimeType = SPEECH_ACTIVATION_TYPE; byte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8")); byte[] id = new byte[0]; byte[] data = new byte[0]; NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, data); NdefMessage m = new NdefMessage(new NdefRecord[] { record }); return m; }
From source file:de.berlin.magun.nfcmime.core.NdefMessageBuilder.java
/** * Builds an NdefMessage from all stored NDEF records. * @return NdefMessage/*from w ww. j a va2s .com*/ */ public NdefMessage buildMessage() { NdefRecord[] records = new NdefRecord[recordlist.size()]; for (int i = 0; i < recordlist.size(); i++) { records[i] = recordlist.get(i); } this.message = new NdefMessage(records); return this.message; }