List of usage examples for android.nfc NdefRecord RTD_TEXT
null RTD_TEXT
To view the source code for android.nfc NdefRecord RTD_TEXT.
Click Source Link
From source file:org.sufficientlysecure.keychain.ui.PassphraseWizardActivity.java
private NdefRecord createRecord(String text) throws UnsupportedEncodingException { //low-level method for writing nfc String lang = "en"; byte[] textBytes = text.getBytes(); byte[] langBytes = lang.getBytes("US-ASCII"); int langLength = langBytes.length; int textLength = textBytes.length; byte[] payload = new byte[1 + langLength + textLength]; // set status byte (see NDEF spec for actual bits) payload[0] = (byte) langLength; // copy langbytes and textbytes into payload System.arraycopy(langBytes, 0, payload, 1, langLength); System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength); return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload); }
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * Build NDEF text record for given parameters * /* ww w . j av a2 s .co 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:edu.cmu.mpcs.dashboard.TagViewer.java
void buildTagViews(NdefMessage[] msgs) { if (msgs == null || msgs.length == 0) { return;//from ww w. j a v a 2 s. c o m } LayoutInflater inflater = LayoutInflater.from(this); // LinearLayout content = mTagContent; // Clear out any old views in the content area, for example if // you scan // two tags in a row. // content.removeAllViews(); // Parse the first message in the list // Build views for all of the sub records Log.i("TEST", "test"); List<ParsedNdefRecord> records = NdefMessageParser.parse(msgs[0]); NdefRecord[] ndefRecords = msgs[0].getRecords(); short tnf = ndefRecords[0].getTnf(); Log.d("RECORD", "tnf is : " + Short.toString(tnf)); byte[] type = ndefRecords[0].getType(); byte[] standard = NdefRecord.RTD_TEXT; System.out.println("printing what we got in the message"); for (byte theByte : type) { System.out.println(Integer.toHexString(theByte)); Log.d("RECORD", Integer.toHexString(theByte)); } System.out.println("printing what the actual val is "); for (byte theByte : standard) { System.out.println(Integer.toHexString(theByte)); Log.d("RECORD", Integer.toHexString(theByte)); } if (ndefRecords[0].getType().equals(standard)) Log.d("RECORD", " type is : RTD_TXT"); else if (ndefRecords[0].getType().equals(NdefRecord.RTD_URI)) Log.d("RECORD", " type is : RTD_URI"); else Log.d("RECORD", " type is : none of the 2"); final int size = records.size(); for (int i = 0; i < size; i++) { ParsedNdefRecord record = records.get(i); Log.i("RECORD", record.toString()); String text; if (record instanceof TextRecord) { TextRecord t = (TextRecord) record; text = t.getText(); } else { UriRecord t = (UriRecord) record; text = t.getUri().toString(); } Log.d("WIFI", text); /* * At this point we have obtained the name of the profile . We * should not append .txt and see if the file exists in the * /mnt/Profile folder. * * If it does exist, then we read the file, and apply various * settings * * If it does note exists, then we show an error message indicating * that the user does not have a profile corresponding to this TAG. * Alternatively: We can take him to the create TAG activity where * he can create a new TAG with this name. */ String contents[] = text.split("#"); String filename = null; if (contents.length > 1) { String readHash = contents[0]; filename = contents[1]; Log.d("TAG_VIEWER", "readHash: " + readHash); Log.d("TAG_VIEWER", "filename: " + filename); if (readHash.equals(Utility.hashOfId)) { Log.d("TAG_VIEWER", "Hash Valid"); File root = Environment.getExternalStorageDirectory(); String path = root + "/Profiles/" + Utility.userUID + "/"; String filePath = path + filename + ".txt"; String settingString = ""; boolean exists = (new File(path).exists()); if (exists) { Log.d("TAG_VIEWER", "Found file:" + filePath); /* * Parse the contents of the file, and apply settings */ try { FileReader logReader = new FileReader(filePath); BufferedReader in = new BufferedReader(logReader); try { settingString = in.readLine(); Log.d("TAG_VIEWER", "In " + filePath + " settingString: " + settingString); } catch (IOException e) { // TODO Auto-generated catch block Log.d("TAG_VIEWER", " read(buf) exception"); e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block Log.d("TAG_VIEWER", "FileReader exception"); e.printStackTrace(); } /* * One call for each setting that we support */ StringBuilder returnVal = new StringBuilder(); returnVal.append(wifiSetting(settingString)); returnVal.append(bluetoothSetting(settingString)); returnVal.append(ringerSetting(settingString)); launchmusicSetting(settingString); returnVal.append(alarmSetting(settingString)); fbSetting(settingString); Log.d("TAG_VIEWER", "the toast should be : " + returnVal.toString()); Context context = getApplicationContext(); CharSequence toastMessage = returnVal; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, toastMessage, duration); toast.show(); } else { /* * Give the user the option of creating a new tag or * ignoring this tag */ } } else { Log.d("TAG_VIEWER", "Hash InValid"); int duration = Toast.LENGTH_LONG; CharSequence msg = "Authentication failure.This tag does not belong to you"; Toast toast = Toast.makeText(TagViewer.this, msg, duration); toast.show(); finish(); // return; } } else { // public tag Log.d("PUBLIC_TAG", "PUBLIC_TAG"); } // For Vibrate mode // /** Sending an SMS to a particular number **/ // Intent intent = new // Intent(Intent.ACTION_VIEW, // Uri.parse("sms:" + "5189515772")); // intent.putExtra("sms_body", // "Hi This is a test message"); // startActivity(intent); /** Toggle Airplane mode **/ // Context context = getApplicationContext(); // boolean isEnabled = // Settings.System.getInt(this.getApplicationContext().getContentResolver(), // Settings.System.AIRPLANE_MODE_ON, 0) == 1; // Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled // ? 0 : 1); // Intent intent = new // Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); // intent.putExtra("state", !isEnabled); // sendBroadcast(intent); /** Launching the browser **/ // String url = "http://www.google.com"; // Intent intent = new // Intent(Intent.ACTION_VIEW); // intent.setData(Uri.parse(url)); // startActivity(intent); /** Check into Facebook **/ // Bundle params = new Bundle(); // // //String access_token = // AndroidDashboardActivity.mPrefs.getString("access_token", // null); // //params.putString("access_token", access_token); // params.putString("place", "203682879660695"); // YOUR PLACE // ID // params.putString("Message","I m here in this place"); // JSONObject coordinates = new JSONObject(); // try // { // coordinates.put("latitude", 40.756); // coordinates.put("longitude", -73.987); // } // catch (JSONException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // params.putString("coordinates",coordinates.toString()); // JSONArray frnd_data=new JSONArray(); // params.putString("tags", "waves.mpcs@gmail.com");//where xx // indicates the User Id // String response; // try // { // response = facebook.request("me/checkins", params, "POST"); // Log.d("Response",response); // } // catch (FileNotFoundException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // catch (MalformedURLException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // catch (IOException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // //Log.d("Response",response); /* * TODO: Hashing TODO: Facebook Auth TODO: File Storage (Profile * Storage) TODO: Sample Profiles TODO: Social Network Check in * TODO: Alarms TODO: Airplane Mode (Enabling NFC while switching to * Airplane mode) TODO: NFC Launcher List (Market App) TODO: UI */ // content.addView(record.getView(this, inflater, content, i)); // inflater.inflate(R.layout.tag_divider, content, true); } }
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 {/*www .j av a 2s . c o m*/ 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; }