- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开发一个可以在 NFC 标签上读写的 android 应用程序。我可以毫无问题地读取我已经写过东西的标签,但是当我使用空白标签时,我很难读取十六进制代码中标签的 UID。
我使用的是 mifare 经典标签,我使用 readblock 方法直接读取十六进制的 UID。奇怪的是,它在我获得 UID 的调试器模式下完美运行。但是当我在没有调试器的情况下尝试时,我得到以下异常:
java.io.IOException: Transceive failed
这是我读入标签的方法:
static String getUID(Intent intent) {
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic mc = MifareClassic.get(tagFromIntent);
try {
mc.connect();
Log.i("connect", "ok");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("connect", "nok");
e.printStackTrace();
}
try {
boolean secA = mc.authenticateSectorWithKeyA(0, mc.KEY_DEFAULT);
Log.i("secA", "ok");
} catch (IOException e) {
Log.i("secA", "nok");
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
boolean secB = mc.authenticateSectorWithKeyB(0, mc.KEY_DEFAULT);
Log.i("secB", "ok");
} catch (IOException e) {
Log.i("secB", "nok");
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] uidBytes = null;
try {
uidBytes = mc.readBlock(0);
Log.i("bytes", "ok");
} catch (IOException e) {
Log.i("bytes", "nok");
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mc.close();
Log.i("close", "ok");
} catch (IOException e) {
Log.i("close", "nok");
// TODO Auto-generated catch block
e.printStackTrace();
}
if (uidBytes != null) {
String uid = HexToString(uidBytes);
return uid;
}
else { return "Repasser le tag";}
}
我不知道如何解决这个问题,因为它在 Debug模式下工作。
最佳答案
这段代码对我有用。在读取 block 之前,您必须检查身份验证。
MifareClassic mif = MifareClassic.get(detectedTag);
int ttype = mif.getType();
Log.d(TAG, "MifareClassic tag type: " + ttype);
int tsize = mif.getSize();
Log.d(TAG, "tag size: " + tsize);
int s_len = mif.getSectorCount();
Log.d(TAG, "tag sector count: " + s_len);
int b_len = mif.getBlockCount();
Log.d(TAG, "tag block count: " + b_len);
try {
mif.connect();
if (mif.isConnected()){
for(int i=0; i< s_len; i++){
boolean isAuthenticated = false;
if (mif.authenticateSectorWithKeyA(i, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY)) {
isAuthenticated = true;
} else if (mif.authenticateSectorWithKeyA(i, MifareClassic.KEY_DEFAULT)) {
isAuthenticated = true;
} else if (mif.authenticateSectorWithKeyA(i,MifareClassic.KEY_NFC_FORUM)) {
isAuthenticated = true;
} else {
Log.d("TAG", "Authorization denied ");
}
if(isAuthenticated) {
int block_index = mif.sectorToBlock(i);
byte[] block = mif.readBlock(block_index);
String s_block = NfcUtils.ByteArrayToHexString(block);
Log.d(TAG, s_block);
}
}
}
mif.close();
} catch (IOException e) {
e.printStackTrace();
}
关于Android NFC java.io.IOException : Transceive failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17401154/
我是 NFC 新手,我想将支持 NFC 的安卓手机作为 NFC 标签,并使用 NFC 阅读器读取其数据。如果您能建议我已经构建的用于发送数据的 NFC 应用程序或我应该使用哪种 NFC 读取器硬件,那
我使用ACR122U工具验证Mifare 1K NFC标签时总是失败,但是我可以用Android手机读写这个标签。 ACR122U Load Authentication Keys 90 00 6
我对 NFC 标准的概述有一些问题。 我所知道的是: ISO/IEC 14443是感应卡的标准,使用 RFID 作为通信协议(protocol); ISO/IEC 18092 (NFCIP-1) 是
我正在尝试实现一个基于通用 NFC 标签的授权系统。我想解决的问题之一是标签克隆。我读过一些文献,通过使用在制造过程中写在标签上的只读标签 ID 来确保标签的真实性。此 ID 由所有者签名并写在标签上
我想为使用 RFID 实现多项功能的系统提案指定设备。它可能会在未来扩展到包括交易,所以我正在努力寻找合适的技术来使用。 计划是使用被动卡。 HF/NFC 卡/读卡器以相同的频率运行,但它们可以互换使
我有一个 ACR122U 阅读器,可以读取很多标签,但不能读取 ICODE SLIX SL2S2002 标签。为什么会这样?我已经在移动设备上尝试过该标签,它被识别出来了。 最佳答案 ICODE SL
NFC Host Card Emulation mode摆脱了本地安全元件 (SE),并通过利用存储在云中的 SE 来促进支付,使用 cooperation几个参与方,例如商家、服务、提供商、发卡机构
Mifare (S50) 1K NFC 卡有 16 个扇区,每个扇区有 4 个 block ,每个 block 保存 16 字节数据。 每个扇区的最后一个 block 是扇区尾部,其中 KeyA 和
我创建的系统存在一些问题。 在登录屏幕等特定页面上,我接受 NFC 卡刷卡以读取 ID 并让用户登录 但是,当用户在未编码 NFC 的页面上扫描卡时,Android 设备会自动最小化我的应用程序并显示
我正在尝试使用 NFC 从血糖仪读取数据,目前在 Android 上,还没有尝试过 iOS(没有带 NFC 的手机)。 我正在使用 react-native-nfc-manager 作为库和它附带的示
这个问题专门针对 MIFARE Ultralight C/EV1,或 MIFARE DESFire EV1,甚至 NTAG 卡。我想实现一个 token 系统,这样每次普通用户读取其中一张卡片时,他们
考虑一名员工使用 NFC 安卓设备通过读取固定在墙上的非接触式 javacard 来报告他的位置,每个人都可以访问。 员工用智能手机扫描javacard,只发送时间戳 非接触式 javacard 接收
有没有办法让 NFC 应用程序读取标签,而不是可以在手机上下载的所有其他应用程序? 通常,如果有多个应用程序可以读取给定标签,系统会提示用户打开哪个应用程序。我想跳过这一步,让我的应用程序自动打开。
我想让我的安卓设备充当 NFC 标签。是否可以使用 NFC 设备作为 NFC 标签?我怎样才能做到这一点?我已经完成了读/写标签,设备之间的光束数据。 最佳答案 这可能是可行的,具体取决于您的 NFC
如果我有 NFC 读取器/写入器设备,我能否让它检测我的支持 NFC 的 Android 手机,以便我可以将数据从我的手机传输到该设备?我在 Stackoverflow 上找到了一些与卡模拟相关的链接
我在 SO 上看到很多关于 NFC 的问题,我遇到的最接近的问题是 Can an Android NFC phone act as an NFC tag? 然而,这个问题是一年多前提出的,当时 Gal
我有一台搭载 Android 4.2 的 Android 平板电脑。此平板电脑没有 NFC 硬件。但是我有一个外部 USB 读卡器:ACR 1252U , 带有 Android library .不幸
据我目前了解,NFC 手机将充当 NFC 阅读器,从 NFC 标签读取数据。现在我的问题是,我们可以改变这个吗?我们能否让 Android NFC 手机充当 NFC 读取器从中获取数据的标签? 感谢您
我被搜索了有关 NFC SIM 卡的信息,发现 such explanations关于他们在这里和那里: For those who want to use near field communicat
Core NFC 是否适用于 iPad? 综上所述,iPad does have NFC chips ,但 Core NFC documentation不说它支持它。 Note Reading NFC
我是一名优秀的程序员,十分优秀!