简体   繁体   English

使用 NFC 配置 Android 设备

[英]Provisioning an Android device using NFC

I have an android device with this app installed on it.我有一个安装了这个应用程序的安卓设备。 Then have a second device that I have factory-reset.然后有第二个设备,我已经恢复出厂设置。 Both are NFC enabled.两者都支持NFC。 And I am trying to provision the second device with a device owner application.我正在尝试使用设备所有者应用程序配置第二个设备。 I want to understand how this works.我想了解这是如何工作的。 I am under the impression that when I bump the two devices together, something should happen.我的印象是,当我将两个设备撞在一起时,应该会发生一些事情。 However, nothing happens.然而,什么也没有发生。 Both devices are on and I believe that I am bumping them in the right places.两个设备都打开了,我相信我在正确的地方碰撞它们。 I have not worked with NFC before.我以前没有使用过 NFC。

On the NFCProvisioning app provided by Google, that I linked above, I can see that the wifi ssid, and password are set in the ndef message.在我上面链接的 Google 提供的 NFCProvisioning 应用程序上,我可以看到在 ndef 消息中设置了 wifi ssid 和密码。 However, the url to the deviceowner app is not set anywhere.但是,设备所有者应用程序的 url 未在任何地方设置。 How will the device being provisioned know how to download the apk?被配置的设备如何知道如何下载 apk?

Also what about this nfcprovisioning.txt?还有这个 nfcprovisioning.txt 怎么样? Please, can someone who has done this before help me out.拜托,之前做过这件事的人可以帮帮我。 Many thanks!非常感谢!

So Now I have more time I can give a full answer.所以现在我有更多的时间可以给出完整的答案。

So some background on Android and NFC first.所以先了解一下 Android 和 NFC 的一些背景知识。

The Android OS has some built in parsing and handling of some types of data on NFC cards, it will handle cards with NDEF messages on them. Android 操作系统内置了一些解析和处理 NFC 卡上某些类型数据的功能,它将处理带有 NDEF 消息的卡。

When an NFC card is presented the OS will attempt to read and understand the card.当出现 NFC 卡时,操作系统将尝试读取和理解该卡。 If there is no App running that has expressed and interest in NFC NDEF messages it will handle some types of NDEF messages in certain was.如果没有正在运行的应用程序表示对 NFC NDEF 消息感兴趣,它将处理某些类型的 NDEF 消息。

Eg If the NDEF message contains record with the Mime Type saying "Web Address" the OS will launch a web browser (or ask the user which web browser to open the URL in)例如,如果 NDEF 消息包含 Mime 类型为“Web 地址”的记录,则操作系统将启动 Web 浏览器(或询问用户在哪个 Web 浏览器中打开 URL)

An NDEF message can also contain an "Android Application Reference" or AAR record, this specifies a package name that should handle the data on the card. NDEF 消息还可以包含“Android 应用程序参考”或 AAR 记录,这指定了应处理卡上数据的包名称。 If that application is not installed it will open up google play to install it.如果未安装该应用程序,它将打开 google play 进行安装。 ( https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar ) https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar

Details on Mime Types and AAR at https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#create-records有关 Mime 类型和 AAR 的详细信息,请访问https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#create-records

This is all done by they OS creating an Intent from the NDEF data and passing it to applications.这一切都是由他们的操作系统从 NDEF 数据创建一个Intent并将其传递给应用程序来完成的。

So more specific to NFCProvisioning creates an NDEF message of a special Mime Type "application/com.android.managedprovisioning" that Android Understands is about Device Provisioning and that to use a package name that is was given or "com.example.android.deviceowner" or "com.example.android.deviceowner/.DeviceOwnerReceiver" if non given.因此,更具体到 NFCProvisioning 创建一个特殊 Mime 类型“application/com.android.managedprovisioning”的 NDEF 消息,Android 理解它是关于设备配置的,并且使用给定的包名称或“com.example.android.deviceowner” " 或 "com.example.android.deviceowner/.DeviceOwnerReceiver" 如果没有给出。

The package name could be one found on the play store but it also has a option to specify a URL to download the management app package from.包名称可以在 Play 商店中找到,但它也可以选择指定用于下载管理应用程序包的 URL。

There is other data included in the NDEF message to Like Wifi details, time zone etc will will be passed on the the Device provisioning app. NDEF 消息中还包含其他数据,例如 Wifi 详细信息、时区等将通过设备配置应用程序传递。 Details of what can be passed is at https://developer.android.com/reference/android/app/admin/DevicePolicyManager#MIME_TYPE_PROVISIONING_NFC I believe可以传递的详细信息在https://developer.android.com/reference/android/app/admin/DevicePolicyManager#MIME_TYPE_PROVISIONING_NFC我相信

The problem you might be suffering is that the method used for the Provisioner device uses to send the data is NfcAdapter#setNdefPushMessage http://developer.android.com/reference/android/nfc/NfcAdapter.html#setNdefPushMessage(android.nfc.NdefMessage,%20android.app.Activity,%20android.app.Activity...) which has been deprecated in API level 29/ Android 10 (and no longer works)您可能遇到的问题是 Provisioner 设备用于发送数据的方法是 NfcAdapter#setNdefPushMessage http://developer.android.com/reference/android/nfc/NfcAdapter.html#setNdefPushMessage(android.nfc. NdefMessage,%20android.app.Activity,%20android.app.Activity...)已在 API 级别 29/Android 10 中弃用(不再有效)

see the issues raised on this https://github.com/android/enterprise-samples/issues/27请参阅此https://github.com/android/enterprise-samples/issues/27上提出的问题

I have not used this process before, but looking at the code the "nfcprovisioning.txt" is just a text file you can load in that stores the values of the key=value pairs instead of having to type them in to the App every time.我以前没有使用过这个过程,但查看代码“nfcprovisioning.txt”只是一个文本文件,你可以加载它存储键=值对的值,而不必每次都将它们输入到应用程序中. eg it would have lines like for that the data you want to provision EXTRA_PROVISIONING_WIFI_SSID=someWifiSSid例如,它会有像你想要提供的数据的行 EXTRA_PROVISIONING_WIFI_SSID=someWifiSSid

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

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