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

前端 未结 2 1344
长情又很酷
长情又很酷 2020-12-02 13:47

I need to know how to set my application as Device owner in Android 5.0, 4.4 and 4.3(?). I\'ve yet tried the method for rooted devices (described in there), successfully. I

相关标签:
2条回答
  • 2020-12-02 14:28

    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.

    Following is the code for NFC trigger

    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 | openssl dgst -binary -sha1 | openssl base64 | tr '+/' '-_' | tr -d '='​

    • Paste the generated checksum in NFC trigger code.
    • Compile and run NFC trigger app on device.

    Now upload your application apk which you want to make as device owner on google drive or dropbox.

    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.

    Your application will be downloaded and will get installed as device owner.

    0 讨论(0)
  • 2020-12-02 14:38

    If it's needed, it's also possible to set a device-owner with adb as mentioned here: http://sdgsystems.com/blog/implementing-kiosk-mode-android-part-3-android-lollipop

    0 讨论(0)
提交回复
热议问题