我如何读取 ISO15693 标签 UID

发布于 2024-12-25 01:23:36 字数 169 浏览 6 评论 0原文

我尝试过使用标签方法

byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);      

,但每次读取标签时值都会发生变化。

如何读取正确的 ISO15693 标签 ID?

I have tried to use the tag method

byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);      

But the value changes every time when I read the tag.

How can I read the correct ISO15693 tags id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空‖城人不在 2025-01-01 01:23:36

获得字节数组后,您需要将十六进制字节数组转换为字符串,

请尝试以下函数:

public String getHexString(byte[] b) {
    StringBuffer sb = new StringBuffer();
    for (int i=b.length-1; i >= 0; i--){
        sb.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
    }
    return sb.toString();
}

After you get the byte array you need to convert the hex byte array to a String

try this function:

public String getHexString(byte[] b) {
    StringBuffer sb = new StringBuffer();
    for (int i=b.length-1; i >= 0; i--){
        sb.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
    }
    return sb.toString();
}
ㄟ。诗瑗 2025-01-01 01:23:36

尝试使用以下

Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

byte[] id = tagFromIntent.getId();

获取标签标识符(如果有)。
标签标识符是低级序列号,用于防碰撞和识别。
大多数标签都有一个稳定的唯一标识符(UID),但有些标签会生成随机ID
每次它们被发现(RID)时,并且有一些标签根本没有ID(字节数组将为零大小)。

Try using the following

Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

byte[] id = tagFromIntent.getId();

Get the Tag Identifier (if it has one).
The tag identifier is a low level serial number, used for anti-collision and identification.
Most tags have a stable unique identifier (UID), but some tags will generate a random ID
every time they are discovered (RID)
, and there are some tags with no ID at all (the byte array will be zero-sized).

晒暮凉 2025-01-01 01:23:36

我碰巧找到了同一问题的解决方案,幸运的是确实找到了我想要的,这是这个问题的解决方案。该解决方案来自此处的另一篇类似帖子。

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    Log.d(TAG, "UID: " + bin2hex(tag.getId()));

    //To display the UID
    static String bin2hex(byte[] data) {
        return String.format("%0" + (data.length * 2) + "X", new BigInteger(1,data));
    }

I happened to find the solution for the same issue and luckily did find what I want, which is a solution to this question. The solution is from another similar post from here.

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    Log.d(TAG, "UID: " + bin2hex(tag.getId()));

    //To display the UID
    static String bin2hex(byte[] data) {
        return String.format("%0" + (data.length * 2) + "X", new BigInteger(1,data));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文