简体   繁体   English

Android 5.0(和其他设备)上的设备所有者使用root设备,通过NFC设备配置

[英]Device Owner on Android 5.0 (and others) whitout rooted devices, device provisioning by NFC

I need to know how to set my application as Device owner in Android 5.0, 4.4 and 4.3(?). 我需要知道如何在Android 5.0,4.4和4.3(?)中将我的应用程序设置为设备所有者。 I've yet tried the method for rooted devices ( described in there ), successfully. 我已经成功地尝试了root设备的方法( 在那里描述 )。 I saw that works great in android 5.0 and 4.4.2 emulator and in CyanoGen AOSP 4.4.4 (all rooted devices). 我看到它在android 5.0和4.4.2模拟器以及CyanoGen AOSP 4.4.4(所有有根设备)中都很有效。 But I must need to try this on other non rooted devices, in Android 5.0 Developer API you can read this 但是我必须在其他非root设备上尝试这个,在Android 5.0 Developer API中你可以读到这个

"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." “要部署和激活设备所有者,您必须在设备处于未设置状态时执行从编程应用程序到设备的NFC数据传输。”

but I don't understand what it means, or better, what I've to do. 但我不明白这意味着什么,或者更好,我要做什么。 Can someone help me, or explain me the step to do? 有人可以帮助我,还是解释我要做的一步?

PS. PS。 I know what NFC is and how it works but I can't understand how to use for this issue. 我知道NFC是什么以及它是如何工作的但是我无法理解如何使用这个问题。

Create a NFC trigger application and install that on a device (other than the one on which you want to make your app as device owner) having NFC. 创建NFC触发器应用程序并将其安装在具有NFC的设备(除了您要将应用程序设置为设备所有者的设备之外)上。

Following is the code for NFC trigger 以下是NFC触发器的代码

public class MainActivity extends Activity implements CreateNdefMessageCallback {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        nfcAdapter.setNdefPushMessageCallback(this, this);
    }

    @Override
    public NdefMessage createNdefMessage(NfcEvent event) {
        try {
            Properties p = new Properties();

            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                    "apk package name");
            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION,
                    "app download url");
            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM,
                    "apk checksum");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            OutputStream out = new ObjectOutputStream(bos);
            p.store(out, "");
            final byte[] bytes = bos.toByteArray();

            NdefMessage msg = new NdefMessage(NdefRecord.createMime(
                    DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));
            return msg;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

For checksum run following command 对于校验和运行以下命令

cat your_device_owner_app_name.apk | cat your_device_owner_app_name.apk | openssl dgst -binary -sha1 | openssl dgst -binary -sha1 | openssl base64 | openssl base64 | tr '+/' '-_' | tr'+ /'' - _'| tr -d '='​ tr -d'='

  • Paste the generated checksum in NFC trigger code. 将生成的校验和粘贴到NFC触发器代码中。
  • Compile and run NFC trigger app on device. 在设备上编译并运行NFC触发器应用程序。

Now upload your application apk which you want to make as device owner on google drive or dropbox. 现在上传你想要在google drive或dropbox上作为设备所有者制作的应用程序apk。

Take a fresh device or factory reset the device on which you want to set your application as device owner. 使用新设备或出厂重置要将应用程序设置为设备所有者的设备。

Reboot the device and on first screen bring your device containing NFC trigger application and touch for beam transfer. 重新启动设备,在第一个屏幕上为您的设备带来NFC触发应用程序和触摸光束传输。

Your application will be downloaded and will get installed as device owner. 您的应用程序将被下载,并将作为设备所有者安装。

如果需要,还可以使用adb设置设备所有者,如下所述: http//sdgsystems.com/blog/implementing-kiosk-mode-android-part-3-android-lollipop

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

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