當前位置: 首頁>>代碼示例>>Java>>正文


Java NdefRecord.RTD_TEXT屬性代碼示例

本文整理匯總了Java中android.nfc.NdefRecord.RTD_TEXT屬性的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.RTD_TEXT屬性的具體用法?Java NdefRecord.RTD_TEXT怎麽用?Java NdefRecord.RTD_TEXT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.nfc.NdefRecord的用法示例。


在下文中一共展示了NdefRecord.RTD_TEXT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTextRecord

/**
 * 創建NDEF文本數據
 *
 * @param text
 * @return
 */
public static NdefRecord createTextRecord(String text) {
    byte[] langBytes = Locale.CHINA.getLanguage().getBytes(Charset.forName("US-ASCII"));
    Charset utfEncoding = Charset.forName("UTF-8");
    //將文本轉換為UTF-8格式
    byte[] textBytes = text.getBytes(utfEncoding);
    //設置狀態字節編碼最高位數為0
    int utfBit = 0;
    //定義狀態字節
    char status = (char) (utfBit + langBytes.length);
    byte[] data = new byte[1 + langBytes.length + textBytes.length];
    //設置第一個狀態字節,先將狀態碼轉換成字節
    data[0] = (byte) status;
    //設置語言編碼,使用數組拷貝方法,從0開始拷貝到data中,拷貝到data的1到langBytes.length的位置
    System.arraycopy(langBytes, 0, data, 1, langBytes.length);
    //設置文本字節,使用數組拷貝方法,從0開始拷貝到data中,拷貝到data的1 + langBytes.length
    //到textBytes.length的位置
    System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length);
    //通過字節傳入NdefRecord對象
    //NdefRecord.RTD_TEXT:傳入類型 讀寫
    NdefRecord ndefRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
            NdefRecord.RTD_TEXT, new byte[0], data);
    return ndefRecord;
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:29,代碼來源:WriteTextActivity.java

示例2: createTextRecord

private NdefRecord createTextRecord (String message)
{
    try
    {
        byte[] language;
        language = Locale.getDefault().getLanguage().getBytes("UTF-8");

        final byte[] text = message.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(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload.toByteArray());
    }
    catch (UnsupportedEncodingException e)
    {
        Log.e("createTextRecord", e.getMessage());
    }
    return null;
}
 
開發者ID:ThomasDelaney,項目名稱:TapIn,代碼行數:25,代碼來源:add3.java

示例3: write

/**
 * Write text to a tag
 *
 * @param textToWrite the text to write
 */
public void write(String textToWrite) {

    Locale locale = Locale.US;
    final byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("UTF-8"));
    final byte[] textBytes = textToWrite.getBytes(Charset.forName("UTF-8"));

    final int utfBit = 0;
    final char status = (char) (utfBit + langBytes.length);
    final 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);
    NdefRecord[] records = {record};
    messageToWrite = new NdefMessage(records);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:23,代碼來源:PNfc.java

示例4: createTextRecord

private NdefRecord createTextRecord(String content) {
    try {
        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(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload.toByteArray());

    } catch (UnsupportedEncodingException e) {
        Log.e("createTextRecord", e.getMessage());
    }
    return null;
}
 
開發者ID:tekesan,項目名稱:TraiNFCUI,代碼行數:21,代碼來源:Tap.java

示例5: getNdefMessageFromText

public NdefMessage getNdefMessageFromText(String messageText)
{
    try
    {
        // Get UTF-8 byte
        byte[] lang = Locale.getDefault().getLanguage().getBytes("UTF-8");
        byte[] text = messageText.getBytes("UTF-8"); // Content in UTF-8

        int langSize = lang.length;
        int textLength = text.length;

        ByteArrayOutputStream payload = new ByteArrayOutputStream(1 + langSize + textLength);
        payload.write((byte) (langSize & 0x1F));
        payload.write(lang, 0, langSize);
        payload.write(text, 0, textLength);
        NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload.toByteArray());
        return new NdefMessage(new NdefRecord[]{record});
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:The-Scrum-Masters,項目名稱:archive-carro-inteligente,代碼行數:23,代碼來源:NFCHandler.java

示例6: buildNdefRecord

/**
 * 構建NdefRecord
 * 
 * @param text
 * @param locale
 * @param encodeInUtf8
 * @return
 */
private NdefRecord buildNdefRecord(String text, 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 = 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);
}
 
開發者ID:11-team,項目名稱:libNfc,代碼行數:24,代碼來源:Nfc.java

示例7: createRecord

private NdefRecord createRecord(String text) throws UnsupportedEncodingException {
    /*
        Note: might want to use "NdefRecord createTextRecord (String languageCode, String text)" instead from NdefRecord.createTextRecord()

     */
    //create the message in according with the standard
    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];
    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);

    NdefRecord recordNFC = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload);
    return recordNFC;
}
 
開發者ID:mofosyne,項目名稱:NFCMessageBoard,代碼行數:22,代碼來源:MainScreen.java

示例8: getTagAsNdef

private NdefMessage getTagAsNdef() {
	boolean addAAR = false;
	String uniqueId = mMD5;
	byte[] uriField = uniqueId.getBytes(Charset.forName("US-ASCII"));
	byte[] payload = new byte[uriField.length + 1];

	System.arraycopy(uriField, 0, payload, 1, uriField.length);

	NdefRecord rtdTextRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
			NdefRecord.RTD_TEXT, new byte[0], payload);

	if (addAAR) {
		// note: returns AAR for different app (nfcreadtag)
		return new NdefMessage(
				new NdefRecord[] {
						rtdTextRecord,
						NdefRecord
						.createApplicationRecord("com.eratosthenes.eventtriggeredskypecaller") });
	} else {
		return new NdefMessage(new NdefRecord[] { rtdTextRecord });
	}
}
 
開發者ID:MikeFot,項目名稱:Android--Event-Triggered-Skype-Caller,代碼行數:22,代碼來源:WriteNFCActivity.java

示例9: newTextRecord

private NdefRecord newTextRecord(String text, 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 = 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);
}
 
開發者ID:donnell74,項目名稱:Org.nized-Android,代碼行數:16,代碼來源:MainActivity.java

示例10: createTextRecord

public NdefRecord createTextRecord(String text) {
	byte[] langBytes = Locale.CHINA.getLanguage().getBytes(
			Charset.forName("US-ASCII"));
	Charset utfEncoding = Charset.forName("UTF-8");
	byte[] textBytes = text.getBytes(utfEncoding);
	int utfBit = 0;
	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 ndefRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
			NdefRecord.RTD_TEXT, new byte[0], data);
	return ndefRecord;
}
 
開發者ID:384401056,項目名稱:itheima,代碼行數:18,代碼來源:ReadWriteTextMainActivity.java

示例11: createTextRecord

public static NdefRecord createTextRecord(String text){
	
	//1.生成語言碼
	byte[] languageByte = Locale.CHINA.getLanguage().getBytes(Charset.forName("US-ASCII"));
	//2.生成狀態碼
	int utfBit = 0;
	char status = (char) (utfBit+languageByte.length);//0+語言編碼長度
	//3.生成文本數據
	byte[] textByte = text.getBytes(Charset.forName("UTF-8"));
	
	byte[] data = new byte[languageByte.length+textByte.length+1];

	data[0] = (byte) status;//設置狀態碼
	System.arraycopy(languageByte, 0, data, 1, languageByte.length);//設置語言編碼
	System.arraycopy(textByte, 0, data, 1+languageByte.length, textByte.length);//設置文本數據
	
	//將data生成一個NdefRecord對象.第三個參數就是一個Record的序號。
	NdefRecord ndefRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);
	
	return ndefRecord;
}
 
開發者ID:384401056,項目名稱:itheima,代碼行數:21,代碼來源:TextRecord.java

示例12: newTextRecord

public static NdefRecord newTextRecord(String text, 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 = 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);
}
 
開發者ID:andresteves,項目名稱:NFC-Reader-and-Chat,代碼行數:16,代碼來源:Beam.java

示例13: newTextRecord

public static NdefRecord newTextRecord(String text, Locale locale, boolean encodeInUTF8) {
  	// Language
      byte[] langBytes = locale.getLanguage().getBytes(CHARSET_US_ASCII);

      // Text
Charset utfEncoding = encodeInUTF8 ? 
		CHARSET_UTF_8 : CHARSET_UTF_16;
      byte[] textBytes = text.getBytes(utfEncoding);

      // Encoding
      int utfBit = encodeInUTF8 ? 0 : (1 << 7);
      char status = (char) (utfBit + langBytes.length);

      // Build NDEF record
      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);
  }
 
開發者ID:andresteves,項目名稱:NFC-Reader-and-Chat,代碼行數:20,代碼來源:TextRecord.java

示例14: createTextRecord

public static NdefRecord createTextRecord(String payload, boolean encodeInUtf8) {
  byte[] langBytes = Locale.getDefault().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;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:14,代碼來源:GingerbreadUtil.java

示例15: createTextRecord

public static 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;
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:14,代碼來源:NFCHelper.java


注:本文中的android.nfc.NdefRecord.RTD_TEXT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。