简体   繁体   English

使用Android获取设备的NFC卡的UID

[英]Get UID of the device's NFC Card with Android

I'm developing an application in which I want to get the NFC serial number of a device. 我正在开发一个想要获取设备NFC序列号的应用程序。 When I press a button, I want the application to find the UID of the NFC card and store it in a DB. 当我按下按钮时,我希望应用程序找到NFC卡的UID并将其存储在DB中。 The only problem is that I have no idea how to get the UID and if that's possible on Android. 唯一的问题是,我不知道如何获取UID,以及在Android上是否可行。

Please read doc: http://developer.android.com/guide/topics/connectivity/nfc/nfc.html 请阅读文档: http : //developer.android.com/guide/topics/connectivity/nfc/nfc.html

Tag have method getId() : Tag有方法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). 大多数标签具有稳定的唯一标识符(UID),但是有些标签每次被发现(RID)时都会生成一个随机ID,并且有些标签根本没有ID(字节数组的大小为零)。

The size and format of an ID is specific to the RF technology used by the tag. ID的大小和格式特定于标签使用的RF技术。

This function retrieves the ID as determined at discovery time, and does not perform any further RF communication or block. 此功能检索在发现时确定的ID,并且不执行任何进一步的RF通信或阻止。

It could be something like this: 可能是这样的:

@Override protected void onNewIntent(Intent intent) {
    if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        Log.d(TAG, "tag ID = " + tag.getId().toString());
    }
    super.onNewIntent(intent);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM