简体   繁体   中英

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. 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.

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. However, the url to the deviceowner app is not set anywhere. How will the device being provisioned know how to download the apk?

Also what about this 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.

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.

When an NFC card is presented the OS will attempt to read and understand the card. 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.

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)

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. If that application is not installed it will open up google play to install it. ( 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

This is all done by they OS creating an Intent from the NDEF data and passing it to applications.

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.

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.

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. Details of what can be passed is at https://developer.android.com/reference/android/app/admin/DevicePolicyManager#MIME_TYPE_PROVISIONING_NFC I believe

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)

see the issues raised on this 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. eg it would have lines like for that the data you want to provision EXTRA_PROVISIONING_WIFI_SSID=someWifiSSid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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