当前位置:网站首页>NFC read / write mode development - book summary
NFC read / write mode development - book summary
2022-06-25 09:53:00 【TowerOs】
Chapter Five: NFC Read write mode
List of articles
Read write mode : The main function is to complete NFC equipment Yes NFC label The operation of
NFC Introduction to read-write mode
- Also known as NFC Reader mode
- Need familiarity NDEF agreement and RTD agreement
Tag Read operations (NDEF data )
- NFC The device is scanned with NDEF When labeling data ,Android It provides support for message parsing
- Learning goals : For any standard Tag Read it
Tag Read operation steps
When NFC The application found a NFC Tag when , It will start the corresponding Activity, stay activity Perform corresponding operations in : For example, using label scheduling system , Define specific IntentFilter
if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction)){
// 1. Definition Tag object
Tag detectedTag = getIntent().getParceableExtra(NfcAdapter.EXTRA_TAG);
// 2. obtain NDEF news
// 3. NDEF Message parsing
// 4. The final real data display and further operation
}
Intent Object can get the following information :
- EXTRA_TAG( necessary ): Representing the scanned label Tag object :
Intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)obtain - EXTRA_NDEF_MESSAGES( Optional ): Is a machine from the label NDEF An array of messages . This additional message is mandatory in Intent On the object :
Intent.getParcebleArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)Acquired - EXTRA_ID( Optional ): Low level of label ID
The above information is guaranteed :Activity It was scanned NFC Intent Object started , Can be in onResume() Add the above code to
NDEF Access to information
String action = intent.getAction();
if(action.equals(NfcAdapter.ACYION_NDEF_DISCOVERED)){
NdefMessage[] message = null;
// take Intent The data in is converted to Parcelable data
Parcelable[] rawMsgs = intent.getParcelbleArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if(rawMsgs != null){
messages = new NdefMessage[rawMsgs.lenth];
for (int i = 0; i < rawMsgs.length; i++){
// take intent The data in is parsed into the corresponding array
messages[i] = (NdefMesage)rawMsgs[i];
}
}else{
byte[] empty = new byte[];
NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
NdefMessage msg = new NdefMessage(new NdefRecord[]{
record });
messages = new NdefMessage[]{
msg};
}
}else if (action.equals(NfcAdapter.ACYION_TECH_DISCOVERED){
}
else if (action.equals(NfcAdapter.ACYION_TAG_DISCOVERED){
}
else {
}
NDEF Message parsing
//TNF_ABSOLUTE_URI Format analysis
byte[] payLoad = record.getPayload();
Uri uri = Uri.parse(new String(payLoad, Charset.forName("UTF-8")));
record.getType();
record.getId();
recode.getTnf();
// TNF_WELL_KNOWN Format analysis
// Verify that the current record is RTD_URI type
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
// analysis payload data
byte[] payload = record.getPayload();
String prefix = URI_PREFIX_MAP.get(payload[0]);
// Splicing the complete recorded data content
byte[] fulluri = Bytes.concat(prefix.getBytes(
Charset.forName("UTF-8")),
Arrays.copyofRange(payload, 1,1 payload.length));
// Convert to URI Encapsulated object
Uri uri = Uri.parse(new String(fulluri, Charset.forName("UTF-8")));
// Other formats are similar , It's all based on NDEF agreement Data analysis
// P96 Page has a complete code example
For the time being
边栏推荐
- Neat Syntax Design of an ETL Language (Part 2)
- 203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?
- Title B of the certification cup of the pistar cluster in the Ibagu catalog
- What should be paid attention to in PMP examination?
- 【mysql学习笔记22】索引
- Test Development Engineer
- [smart agriculture program] smart agriculture small program project is currently popular.
- 使用EVO
- Nano data World Cup data interface, CSL data, sports data score, world cup schedule API, real-time data interface of football match
- Shuttle JSON, list, map inter transfer
猜你喜欢

Online notes on Mathematics for postgraduate entrance examination (9): a series of courses on probability theory and mathematical statistics

Jetpack compose layout (I) - basic knowledge of layout
![[buuctf.reverse] 117-120](/img/6c/8a90fff2bd46f1494a9bd9c77eeafc.png)
[buuctf.reverse] 117-120

Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary

Nano data World Cup data interface, CSL data, sports data score, world cup schedule API, real-time data interface of football match

CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded

瑞吉外卖项目(二)

Remove the mosaic, there's a way, attached with the running tutorial

Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL

How much money have I made by sticking to fixed investment for 3 years?
随机推荐
Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
Is GF Securities reliable? Is it legal? Is it safe to open a stock account?
Wechat official account can reply messages normally, but it still prompts that the service provided by the official account has failed. Please try again later
CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded
Chitubox micromake l3+ slicing software configuration correspondence
Get started quickly with jetpack compose Technology
MySQL创建给出语句
Cocopod error failed: undefined method `map 'for nil:nilclass
Is it safe to open an account with Great Wall Securities by mobile phone?
Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021
字符串 实现 strStr()
Fluent creates, reads and writes JSON files
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
JS tool function, self encapsulating a throttling function
Applet cloud development joint table data query and application in cloud function
Is it safe for Huatai Securities to open an account on it? Is it reliable?
The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores
力扣-104. 二叉树的最大深度
Force buckle -104 Maximum depth of binary tree
Flutter replaces the default icon of Gaud positioning