android nfc常用標籤讀取

2021-07-17 03:52:30 字數 4304 閱讀 5548

nfc的基本介紹就不做說明了,網上有很多資料,下面主要描述nfc資料過濾、ndef資料讀取和非ndef資料讀取:

1、nfc資料過濾

nfc主要有三種過濾器,分別是ndef_discovered,tech_

discovered,tag_discovered,主要說明如下:

ndef_discovered:當檢測到標籤中含有ndef格式的資料,並且在應用中宣告了可以接收ndef資料的intent時,觸發該action的intent;

tech_

discovered:當沒有應用響應ndef_discovered時,會發出tech的intent;

tag_

discovered:當前兩個intent都沒有觸發時,預設觸發tag型別的intent;

(1) ndef_discovered過濾定義:

(2)tech_

discovered過濾定義:

nfc_tech_filter檔案:

<?xml version="1.0" encoding="utf-8"?>

android.nfc.tech.isodep

android.nfc.tech.nfca

android.nfc.tech.nfcb

android.nfc.tech.nfcf

android.nfc.tech.nfcv

android.nfc.tech.ndef

android.nfc.tech.ndefformatable

android.nfc.tech.mifareclassic

android.nfc.tech.mifareultralight

(3)tag_

discovered過濾:

2、各類nfc資料讀取

(1)ndef資料讀取

tnf_absolute_uri讀取:

private void parseabsoluteurirecode(ndefrecord record)

tnf_well_known的uri讀取:

private void parsewellknownurirecode(ndefrecord record)

tnf_well_known的text讀取: 

private void parsewellknowntextrecode(ndefrecord record)  catch (unsupportedencodingexception e) 

setnotebody(payloadstr);

}

tnf_absolute_uri的record型別和tnf_external_type型別讀取:

private void parseotherrecode(ndefrecord record)
(2)非ndef資料讀取

mifareultralight讀取:

public string readtagultralight(tag tag)  catch (ioexception e)  catch (exception ee)  finally  catch (ioexception e) 

}} }

mifareclassic讀取:

public string readtagclassic(tag tag) 

metainfo += "卡片型別:" + types + "\n共" + sectorcount + "個扇區\n共"

+ mfc.getblockcount() + "個塊\n儲存空間: " + mfc.getsize()

+ "b\n";

for (int j = 0; j < sectorcount; j++)

} else

}return metainfo;

} catch (exception e) finally catch (ioexception e)

}} return null;

}

isodep讀取:

isodep isodep = isodep.get(tagfromintent);

isodep.connect();

byte mf = ;

string result="";

byte mfrsp = isodep.transceive(getselectcommand(mf));

log.d(tag, "mfrsp:" + hextostring(mfrsp));

byte wht = ;

byte sztrsp = isodep.transceive(getselectcommand(wht));

byte balance = ;

byte balancersp = isodep.transceive(balance);

log.d(tag, "balancersp:" + hextostring(balancersp));

if(balancersp!=null && balancersp.length>4)

setnotebody(result);

isodep.close();

nfcb讀取:

nfcbtag = nfcb.get(tag);

try

// nfcbtag.close();

} catch (ioexception e)

nfca讀取:

nfca nfca = nfca.get(tagfromintent);

try;

byte response = nfca.transceive(select);

nfca.close();

if(response!=null)}}

catch(exception e)

nfcf讀取:

nfcf nfc = nfcf.get(tag);

try ;

byte req = readwithoutencryption(felicaidm, 10);

byte res = nfc.transceive(req);

nfc.close();

setnotebody(bytearraytohexstring(res));

} catch (exception e)

nfcv讀取:

nfcv tech = nfcv.get(tag);

if (tech != null) ;

system.arraycopy(taguid, 0, cmd, 2, taguid.length); // paste tag uid into command

byte response = tech.transceive(cmd);

tech.close();

if(response!=null)

}} catch (ioexception e)

}

ndef與ndefformatable讀取:

ndefmessage messages = ge***efmessages(getintent());

byte payload = messages[0].getrecords()[0].getpayload();

setnotebody(new string(payload));

ndefmessage ge***efmessages(intent intent) 

} else ;

ndefrecord record = new ndefrecord(ndefrecord.tnf_unknown, empty, empty, empty);

ndefmessage msg = new ndefmessage(new ndefrecord );

msgs = new ndefmessage ;

}} else

return msgs;

}

jsp常用標籤

把另乙個資源的輸出內容插入進當前jsp頁面的輸出內容之中,這種在jsp頁面執行時的引入方式叫做動態引入 動態引入和靜態引入的區別 靜態引用是在編譯jsp前簡單地把源 包含進來 動態引用是在執行時,把web請求和響應物件傳過去,對請求和相應物件進一步處理 也就是說,靜態引用,引用的 是什麼,引用進來就...

html常用標籤

總類 所有html檔案都有的 檔案型別 放在檔案的開頭與結尾 檔案主題 必須放在 文頭 區塊內 文頭 描述性資料,像是 主題 文體 檔案本體 結構性定義 由瀏覽器控制的顯示風格 標題 從1到6,有六層選擇 3.0 標題的對齊 3.0 區分 3.0 區分的對齊 引文區塊 通常會內縮 強調 通常會以斜體...

struts常用標籤

常用的struts標籤有logic標籤,html標籤,bean標籤 在需要使用標籤的應用,首先需要把標籤庫對應三類標籤是三個tld檔案拷貝到web inf目錄下 在需要使用標籤的頁面,檔案前得加上標籤庫的引入說明如下 taglib uri web inf struts bean.tld prefix...