List of usage examples for android.nfc NdefRecord TNF_WELL_KNOWN
short TNF_WELL_KNOWN
To view the source code for android.nfc NdefRecord TNF_WELL_KNOWN.
Click Source Link
Use this tnf with RTD types such as #RTD_TEXT , #RTD_URI .
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * Build NDEF text record for given parameters * /*from w w w. j a v a 2 s. c o m*/ * @param text * @param locale * @param encodeInUtf8 * @return */ private NdefRecord buildTextRecord(String text, Locale locale, boolean encodeInUtf8) { Log.d(CLASSNAME, "buildTextRecord is called Text:" + text + " Locale:" + locale.toString() + " encodeinUtf8:" + encodeInUtf8); byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII")); Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16"); byte[] textBytes = text.getBytes(utfEncoding); int utfBit = encodeInUtf8 ? 0 : (1 << 7); char status = (char) (utfBit + langBytes.length); byte[] data = new byte[1 + langBytes.length + textBytes.length]; data[0] = (byte) status; System.arraycopy(langBytes, 0, data, 1, langBytes.length); System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length); return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data); }
From source file:com.example.mynsocial.BluetoothChat.java
NdefMessage create_RTD_TEXT_NdefMessage(String inputText) { Log.e(TAG, "+++ create_RTD +++"); Locale locale = new Locale("en", "US"); byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII")); boolean encodeInUtf8 = false; Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16"); int utfBit = encodeInUtf8 ? 0 : (1 << 7); byte status = (byte) (utfBit + langBytes.length); byte[] textBytes = inputText.getBytes(utfEncoding); byte[] data = new byte[1 + langBytes.length + textBytes.length]; data[0] = (byte) status; System.arraycopy(langBytes, 0, data, 1, langBytes.length); System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length); NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data); NdefMessage message = new NdefMessage(new NdefRecord[] { textRecord }); return message; }
From source file:com.example.multi_ndef.Frag_Write.java
public NdefRecord createTextRecord(String payload, Locale locale, boolean encodeInUtf8) { byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII")); Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16"); byte[] textBytes = payload.getBytes(utfEncoding); int utfBit = encodeInUtf8 ? 0 : (1 << 7); char status = (char) (utfBit + langBytes.length); byte[] data = new byte[1 + langBytes.length + textBytes.length]; data[0] = (byte) status; System.arraycopy(langBytes, 0, data, 1, langBytes.length); System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length); NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data); return record; }
From source file:com.mario22gmail.license.nfc_project.NavigationDrawerActivity.java
private NdefRecord createTextRecord(String content) { try {/*w w w .jav a 2s.c om*/ byte[] language; language = Locale.getDefault().getLanguage().getBytes("UTF-8"); final byte[] text = content.getBytes("UTF-8"); final int languageSize = language.length; final int textLength = text.length; final ByteArrayOutputStream payload = new ByteArrayOutputStream(1 + languageSize + textLength); payload.write((byte) (languageSize & 0x1F)); payload.write(language, 0, languageSize); payload.write(text, 0, textLength); return new NdefRecord(android.nfc.NdefRecord.TNF_WELL_KNOWN, android.nfc.NdefRecord.RTD_TEXT, new byte[0], payload.toByteArray()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.e("create text record", e.getMessage()); } return null; }