Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

android - How to make my app a device owner?

The device policy manager API docs and the android 5.0 overview both mention something about a device owner app. How can I setup my app as a device owner?

Edit: Is there any other ways than rooting and NFC if available please share.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's actually a way other than NFC and rooting to set an application as a device owner app. You could use the dpm command line tool from an adb shell.

Usage :

usage: dpm [subcommand] [options]
usage: dpm set-device-owner <COMPONENT>
usage: dpm set-profile-owner <COMPONENT> <USER_ID>

dpm set-device-owner: Sets the given component as active admin, and its package as device owner.
dpm set-profile-owner: Sets the given component as active admin and profile owner for an existing user.

UPDATE : The dpm utility is really simple actually. Its goal is to create a new file called device_owner.xml under /data/system/device_owner.xml that references the Device/Profile owner apps.

The Android platform is then reading this file to check which application is considered as a Device Owner or Profile Owner App.

On a rooted device, you could indeed create this file by yourself, but since the dpm tool is doing it, you'd better use it (DRY principle) :

For example via a Runtime.exec() command:

Runtime.getRuntime().exec("dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr");

Also notice that this tool is working only if no account is set for the user (make sure no account is set in Settings > Accounts) before its use.

Source and more information at Android shell command tool : Device Policy Manager


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...