**
通过手机的NFC功能是否能够读取RFID标签
**
可以读取部分标签
RFID标签有多种类型:依据频率的不同可分为低频(LF)、高频(HF)、超高频(UHF)、微波(MW)电子标签。
1、高频卡典型工作频率为:13.56MHz ,是现在国内应用最成熟广泛的卡片,卡片的种类也非常多。
2、低频卡频率一般在135K赫兹以下,比较典型的125赫兹的ID卡应用非常广泛。这种卡片只有一个固化序列号可以被设备读出
3、超高频和微波标签其典型工作频率为:433MHz,900MHz,2.45GHz,5.8GHz,读卡距离最大可达10m以上。 此类标签典型应用包括:物流和供应管理、生产制造和装配、航空行李处理、邮件、快运包裹处理、文档追踪、门禁控制、电子门票、道路自动收费等等。此类标签技术是现在物联网不可缺少的部分。
其中,像校园卡这种高频13.56MHz的校园卡可以被手机的NFC功能读取。(但不只是13.56MHz,实测还有其他频段也有可以的)
接下来我们来剖析如何利用安卓的NFC功能和高频卡片交互吧!
最好不要尝试乱写自己的校园卡!!!读一下就算了!
安卓代码
实验环境
Android Studio开发工具
项目文件夹
代码
首先在 AndroidManifest.xml 文件中申请我们需要的权限
1
2
3
4
5
6
7
8<!--NFC基本权限--> <uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> <!--震动权限--> <uses-permission android:name="android.permission.VIBRATE" />
设计一下主界面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/bt_write_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="写入NDEF格式数据" /> ......省略...... </LinearLayout>
读取界面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="请将手机贴近NFC标签" android:textColor="@android:color/darker_gray" android:textSize="20sp" /> <TextView android:id="@+id/rv_read" android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout>
写入界面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/et_data" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:onClick="onClick" android:id="@+id/bt_write_text" android:text="写入" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
BaseNFCActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73package com.ljb.nfcreadandwritedemo; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; import android.widget.Toast; import utils.NFCHelper; /** * Created by ljb on 2018/8/1. */ public class BaseNFCActivity extends AppCompatActivity { protected NFCHelper nfcHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); nfcHelper = new NFCHelper(this); } @Override protected void onResume() { super.onResume(); //判断设备是否支持NFC功能 if (nfcHelper.isSupportNFC()) { //判断设备是否开启NFC功能 if (nfcHelper.isEnableNFC()) { //注册FNC监听器 nfcHelper.registerNFC(this); } else { nfcHelper.showFNCSetting(this); } } else { showToast("当前设备不支持NFC功能"); } } @Override protected void onPause() { super.onPause(); nfcHelper.unRegisterNFC(this); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); log("Action: " + intent.getAction()); } public void start(Class clazz) { startActivity(new Intent(this, clazz)); } public void showToast(String content) { if (TextUtils.isEmpty(content)) return; Toast.makeText(this, content, Toast.LENGTH_SHORT).show(); } public void log(String content) { Log.e(getClass().getSimpleName(), content); } }
ReadMUActivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38package com.ljb.nfcreadandwritedemo.read; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.View; import android.widget.TextView; import com.ljb.nfcreadandwritedemo.BaseNFCActivity; import com.ljb.nfcreadandwritedemo.R; /** * Created by ljb on 2018/8/3. */ public class ReadMUActivity extends BaseNFCActivity { private TextView tvRead; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read); tvRead = findViewById(R.id.rv_read); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); String ret = nfcHelper.readNFC_MU(intent); if (ret != null) { nfcHelper.vibrate(this); tvRead.setText("内容为: " + ret); } } }
根据上面的代码我们就可以简单的读取校园卡的卡号。
代码太多就不再一一粘贴。
完整源码请在微信公众号“修电脑的杂货店”后台回复“代码”获取!!!
对这篇内容对你有帮助,或者对本公众号内容有兴趣的同学可以加入官方QQ群详细交流探讨,互相学习共同进步,源码和具体操作流程,也会放到群里,如果有不懂得细节,群里也会有人回答。快加入我们的大家庭QQ群号:559369389 欢迎新成员的到来!
最后
以上就是忐忑金毛最近收集整理的关于安卓手机APP读写高频RFID标签(校园卡)NDEF格式数据设计的全部内容,更多相关安卓手机APP读写高频RFID标签(校园卡)NDEF格式数据设计内容请搜索靠谱客的其他文章。
发表评论 取消回复