激活使用NFC在Android棒棒糖设备所有者 [英] Activate a device owner using NFC on Android Lollipop

查看:255
本文介绍了激活使用NFC在Android棒棒糖设备所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用NFC的设备上设置的设备所有者包。在中提到的棒棒糖概述这里

I am trying to set the device owner package on a device using NFC. The is mentioned in the Lollipop overview here:

要部署并激活设备所有者,您必须执行的NFC数据   从编程的应用程序传送到该设备,而该设备处于   其未接通的状态。此数据传输发送相同的信息   如在管理配置中所述的配置意图。

To deploy and activate a device owner, you must perform an NFC data transfer from a programming app to the device while the device is in its unprovisioned state. This data transfer sends the same information as in the provisioning intent described in Managed provisioning.

原因是一旦设置,你可以使用屏幕锁定特征锁定装置在kiosk模式。我已经能够通过将device_owner.xml文件数据/系统/一个植根设备上手动设置设备所有者,以测试这种kiosk模式。

The reason is once this is set you can use the screen pinning feature to lock the device in a kiosk mode. I have been able to test the this kiosk mode by manually setting the device owner by placing a device_owner.xml file to data/system/ on a rooted device.

我从来没有使用NFC之前,所以我可以的路要走,但我想出了以下NdefMessage基础上的信息<一个href="http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#MIME_TYPE_PROVISIONING_NFC"相对=nofollow>这里:

I have never used NFC before so I may be way off but I came up with the following NdefMessage based on the info here:

Properties properties = new Properties();
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.my.package");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, "MyWiFiSSID");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD, "WifiPassword");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, "C9AD9E082457819B54CF76255A400375E4127112");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, "https://dl.dropboxusercontent.com/u/xxx/app-release.apk");


ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(properties);
byte[] yourBytes = bos.toByteArray();
NdefRecord ndefRecord = NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, yourBytes);
NdefMessage msg = new NdefMessage(ndefRecord);

发送这,我刚刚恢复与棒棒堂preVIEW使其显示设备:

Sending this to a device that I have just restored with the Lollipop preview causes it to show:

哎呀!无法设置您的设备。请联系您的IT部门。

Oops! Couldn't set up your device. Contact your IT department.

它似乎是承认事实,即它正在接收规定的要求,但我不认为这是看完我设置的属性,它不会尝试连接上wifi。

Its seems to be recognising the fact that it is receiving a provision request, but I do not think it is reading the properties I set, it does not try to connect the the wifi.

推荐答案

看来你需要使用 Properties.store 来正确地创建字节的NdefRecord。

It appears you need to use the Properties.store to correctly create the bytes for the NdefRecord.

Properties properties = new Properties();
properties.setProperty(...);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStream out = new ObjectOutputStream(bos);
properties.store(out, "");
byte[] bytes = bos.toByteArray();

NdefMessage msg = new NdefMessage(NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));

目前,我有一个问题,它下载我的APK和校验失败。一点也不知道为什么。

Currently, I'm having an issue with it downloading my APK and the checksum failing. Not at all sure why.

这篇关于激活使用NFC在Android棒棒糖设备所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆