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


Java NdefRecord.TNF_WELL_KNOWN屬性代碼示例

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


在下文中一共展示了NdefRecord.TNF_WELL_KNOWN屬性的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: createUriRecord

/**
 * 將Uri轉成NdefRecord
 *
 * @param uriStr
 * @return
 */
public static NdefRecord createUriRecord(String uriStr) {
    byte prefix = 0;
    for (Byte b : UriPrefix.URI_PREFIX_MAP.keySet()) {
        String prefixStr = UriPrefix.URI_PREFIX_MAP.get(b).toLowerCase();
        if ("".equals(prefixStr))
            continue;
        if (uriStr.toLowerCase().startsWith(prefixStr)) {
            prefix = b;
            uriStr = uriStr.substring(prefixStr.length());
            break;
        }
    }
    byte[] data = new byte[1 + uriStr.length()];
    data[0] = prefix;
    System.arraycopy(uriStr.getBytes(), 0, data, 1, uriStr.length());
    NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], data);
    return record;
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:24,代碼來源:WriteUriActivity.java

示例4: parseTextRecord

private String parseTextRecord(NdefRecord record){
    String response=null;
    // 驗證TNF是否為TNF_WELL_KNOWN
    if(record.getTnf()!=NdefRecord.TNF_WELL_KNOWN) {
        System.out.println("不是TNF_WELL_KNOW");
        return null;
    }

    byte[] payload=record.getPayload();
    Byte statusByte=payload[0];
    String textCoding=((statusByte&0x80)==0)?"utf-8":"utf-16";
    int codeLength=statusByte&0x3f;
    try{
        response=new String(payload,codeLength+1,payload.length-codeLength-1,textCoding);
    }
    catch(UnsupportedEncodingException e){
        Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
    }
    return response;
}
 
開發者ID:Quick-Tip,項目名稱:Quick-Tip-Consumer,代碼行數:20,代碼來源:NFCReadActivity.java

示例5: 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

示例6: 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

示例7: parseNdefRecord

private static String parseNdefRecord(Context ctx, NdefRecord record) {
    if(record.getTnf() == NdefRecord.TNF_WELL_KNOWN) {
        if(Arrays.equals(record.getType(),NdefRecord.RTD_URI)) {
            return parseWellKnownUriRecord(ctx,record);
        }
        else if (Arrays.equals(record.getType(),NdefRecord.RTD_TEXT)) {
            return parseWellKnownTextRecord(ctx, record);
        }
        else {
            return parseGenericNdefRecord(ctx,record);
        }
    }
    else {
        return parseGenericNdefRecord(ctx,record);
    }
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:16,代碼來源:TcmpMessageDescriptor.java

示例8: parseTnf

private static String parseTnf(Context ctx, NdefRecord record) {
    short tnf = record.getTnf();
    switch(tnf) {
        case NdefRecord.TNF_ABSOLUTE_URI:
            return ctx.getString(R.string.tnf_abs_uri);
        case NdefRecord.TNF_EMPTY:
            return ctx.getString(R.string.tnf_empty);
        case NdefRecord.TNF_EXTERNAL_TYPE:
            return ctx.getString(R.string.tnf_external);
        case NdefRecord.TNF_MIME_MEDIA:
            return ctx.getString(R.string.tnf_mime_media);
        case NdefRecord.TNF_UNCHANGED:
            return ctx.getString(R.string.tnf_unchanged);
        case NdefRecord.TNF_WELL_KNOWN:
            return ctx.getString(R.string.tnf_well_known);
        default:
            return ctx.getString(R.string.tnf_unknown);
    }
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:19,代碼來源:TcmpMessageDescriptor.java

示例9: nfcRead

public String nfcRead(Tag t)
{
    Tag tag = t;
    Ndef ndef = Ndef.get(tag);
    if (ndef == null) {
        return null;
    }
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();
    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records)
    {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
        {
            try {return readText(ndefRecord);} catch (UnsupportedEncodingException e) {}
        }
    }

    return null;

}
 
開發者ID:tawaasalage,項目名稱:RxBluetoothAuto,代碼行數:20,代碼來源:Home.java

示例10: 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

示例11: getTagText

public String getTagText() throws Exception
{
    if (tag == null)
    {
        throw new Exception("Please call handle new read as tag is null");
    }
    Ndef ndef = Ndef.get(tag);
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records)
    {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
        {
            try
            {
                return readText(ndefRecord);
            }
            catch (UnsupportedEncodingException e)
            {
                Toast.makeText(activity, "Unsupported encoding", Toast.LENGTH_SHORT).show();
            }
        }
    }
    return null;
}
 
開發者ID:The-Scrum-Masters,項目名稱:archive-carro-inteligente,代碼行數:26,代碼來源:NFCHandler.java

示例12: doInBackground

@Override
protected ArrayList<String> doInBackground(Tag... params) {
    Tag tag = params[0];

    Ndef ndef = Ndef.get(tag);
    if (ndef == null) {
        // NDEF is not supported by this Tag.
        return null;
    }

    ArrayList<String> results = new ArrayList<>();
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();
    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records) {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
            try {
                results.add(readText(ndefRecord));
            } catch (UnsupportedEncodingException e) {
                Log.e(TAG, "Unsupported Encoding", e);
            }
        }
    }

    return results;
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:25,代碼來源:NfcReadNdefAsyncTask.java

示例13: toNfcRecord

/**
 * Converts android.nfc.NdefRecord to mojo NfcRecord
 */
private static NfcRecord toNfcRecord(NdefRecord ndefRecord)
        throws UnsupportedEncodingException {
    switch (ndefRecord.getTnf()) {
        case NdefRecord.TNF_EMPTY:
            return createEmptyRecord();
        case NdefRecord.TNF_MIME_MEDIA:
            return createMIMERecord(
                    new String(ndefRecord.getType(), "UTF-8"), ndefRecord.getPayload());
        case NdefRecord.TNF_ABSOLUTE_URI:
            return createURLRecord(ndefRecord.toUri());
        case NdefRecord.TNF_WELL_KNOWN:
            return createWellKnownRecord(ndefRecord);
    }
    return null;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:18,代碼來源:NfcTypeConverter.java

示例14: readTag

private void readTag(Tag t) {
    byte[] id = t.getId();

    // get NDEF tag details
    Ndef ndefTag = Ndef.get(t);

    // get NDEF message details
    NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
    if (ndefMesg == null) {
        return;
    }
    NdefRecord[] ndefRecords = ndefMesg.getRecords();
    if (ndefRecords == null) {
        return;
    }
    for (NdefRecord record : ndefRecords) {
        short tnf = record.getTnf();
        String type = new String(record.getType());
        if (tnf == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(type.getBytes(), NdefRecord.RTD_URI)) {
            String url = new String(record.getPayload());
            recordBadge(url);
        }
    }
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:24,代碼來源:NfcBadgeActivity.java

示例15: 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


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