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


Java NdefRecord.getTnf方法代碼示例

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


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

示例1: parseTextRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:21,代碼來源:NFCReadActivity.java

示例2: extractMimePayload

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Nullable
public static byte[] extractMimePayload(final String mimeType, final NdefMessage message) {
    final byte[] mimeBytes = mimeType.getBytes(Charsets.US_ASCII);

    for (final NdefRecord record : message.getRecords()) {
        if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA && Arrays.equals(record.getType(), mimeBytes))
            return record.getPayload();
    }

    return null;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:12,代碼來源:Nfc.java

示例3: parseNdefRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static byte[] parseNdefRecord(final NdefRecord record) {
    if (record.getTnf() != NdefRecord.TNF_EXTERNAL_TYPE) {
        throw new IllegalArgumentException("Invalid TNF: " + record.getTnf());
    }
    final byte[] type = record.getType();
    if (type == null) {
        throw new NullPointerException("Type must not be null");
    }
    final String typeString = new String(type);
    if (!typeString.equalsIgnoreCase(BuildConfig.APPLICATION_ID + ":stream")) {
        throw new IllegalArgumentException("Invalid type: " + typeString);
    }

    final byte[] bytes = record.getPayload();
    if (bytes == null) {
        throw new NullPointerException("Payload must not be null");
    }
    return bytes;
}
 
開發者ID:felixb,項目名稱:basscast,代碼行數:20,代碼來源:Stream.java

示例4: parseNdefRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:17,代碼來源:TcmpMessageDescriptor.java

示例5: parseTnf

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:20,代碼來源:TcmpMessageDescriptor.java

示例6: parseType

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static String parseType(Context ctx, NdefRecord record) {
    byte[] type = record.getType();
    if(Arrays.equals(type, NdefRecord.RTD_URI))
        return ctx.getString(R.string.rtd_uri);
    else if(Arrays.equals(type,NdefRecord.RTD_ALTERNATIVE_CARRIER))
        return ctx.getString(R.string.rtd_alt_carrier);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_CARRIER))
        return ctx.getString(R.string.rtd_handover_carrier);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_REQUEST))
        return ctx.getString(R.string.rtd_handover_request);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_SELECT))
        return ctx.getString(R.string.rtd_handover_select);
    else if(Arrays.equals(type,NdefRecord.RTD_SMART_POSTER))
        return ctx.getString(R.string.rtd_smart_poster);
    else if(Arrays.equals(type,NdefRecord.RTD_TEXT))
        return ctx.getString(R.string.rtd_text);
    else if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA)
        return new String(type);
    else
        return ByteUtils.bytesToHex(type);
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:22,代碼來源:TcmpMessageDescriptor.java

示例7: nfcRead

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:21,代碼來源:Home.java

示例8: getTagText

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:27,代碼來源:NFCHandler.java

示例9: doInBackground

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@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,代碼行數:26,代碼來源:NfcReadNdefAsyncTask.java

示例10: toNfcRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
 * 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,代碼行數:19,代碼來源:NfcTypeConverter.java

示例11: readTag

import android.nfc.NdefRecord; //導入方法依賴的package包/類
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,代碼行數:25,代碼來源:NfcBadgeActivity.java

示例12: doInBackground

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected 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;
    }

    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) {
                //Log.e(TAG, "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:mofosyne,項目名稱:NFCMessageBoard,代碼行數:26,代碼來源:MainScreen.java

示例13: doInBackground

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected 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;
    }

    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) {
                Log.e(TAG, "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:hkboy,項目名稱:NFCPoC,代碼行數:26,代碼來源:MainActivity.java

示例14: getRecords

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static List<ParsedNdefRecord> getRecords(NdefRecord[] records) {
        List<ParsedNdefRecord> elements = new ArrayList<ParsedNdefRecord>();
        
        for (NdefRecord record : records) {
        	
        	if(record.getTnf() != NdefRecord.TNF_WELL_KNOWN){
        		Log.e("TNF_NOT_KNOWN", "This tag has a TNF not known!");
        		return elements;
        	}
        	        	
//        	if(record.getType().equals(NdefRecord.RTD_URI)) {
//                elements.add(UriRecord.parse(record));
//            }
//        	if (record.getType().equals(NdefRecord.RTD_TEXT)) {
                elements.add(TextRecord.parse(record));
//            }
//        	if (record.getType().equals(NdefRecord.RTD_SMART_POSTER)) {
//                elements.add(SmartPoster.parse(record));
//            }
        }
        return elements;
    }
 
開發者ID:andresteves,項目名稱:NFC-Reader-and-Chat,代碼行數:23,代碼來源:NdefMessageParser.java

示例15: parse

import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
 * 解析NdefRecord中Uri數據
 *
 * @param record
 * @return
 */
public static Uri parse(NdefRecord record) {
    short tnf = record.getTnf();
    if (tnf == NdefRecord.TNF_WELL_KNOWN) {
        return parseWellKnown(record);
    } else if (tnf == NdefRecord.TNF_ABSOLUTE_URI) {
        return parseAbsolute(record);
    }
    throw new IllegalArgumentException("Unknown TNF " + tnf);
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:16,代碼來源:ReadUriActivity.java


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