当前位置:网站首页>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
边栏推荐
- Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
- Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
- Get started quickly with jetpack compose Technology
- Etcd tutorial - Chapter 4 etcd cluster security configuration
- 独步武林,架构选型手册(包含 PDF)
- Exception: gradle task assemblydebug failed with exit code 1
- 8. Intelligent transportation project (1)
- Arduino bootloader burning summary
- 51 SCM time stamp correlation function
- Flutter replaces the default icon of Gaud positioning
猜你喜欢

Learning notes of rxjs takeuntil operator

Chitubox micromake l3+ slicing software configuration correspondence

Download the arm64 package of Debian on X86 computer

Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.

2022 meisai question a idea sharing

Flutter dialog: cupertinoalertdialog

Study on correlation of pumpkin price and design of price prediction model based on BP neural network

可穿戴设备或将会泄露个人隐私

Jetpack compose layout (II) - material components and layout

manhattan_ Slam environment configuration
随机推荐
Data-driven anomaly detection and early warning of 21 May Day C
汇付国际为跨境电商赋能:做合规的跨境支付平台!
Chitubox micromake l3+ slicing software configuration correspondence
clang frontend command failed with exit code 250
Is it safe to open an account on the compass?
[matlab] image binarization (imbinarize function)
【mysql学习笔记21】存储引擎
Creo makes a mobius belt in the simplest way
Analysis on the thinking of 2022 meisai C question
How to download the school logo, school name and corporate logo on a transparent background without matting
[MySQL learning notes 20] MySQL architecture
Etcd教程 — 第四章 Etcd集群安全配置
Exception: gradle task assemblydebug failed with exit code 1
Methodchannel of flutter
Creating a binary tree (binary linked list) from a generalized table
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
Remove the mosaic, there's a way, attached with the running tutorial
Best producer consumer code
富时A50开户什么地方安全
Minio基本使用与原理