How to make my app a device owner?
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
How to make my app device owner without NFC and ADB shell command?
The source code says, 'Device owner can only be set on an unprovisioned device, unless it was initiated by “adb”, in which case we allow it if no account is associated with the device'
If you don't have any accounts set up, you can set it programmatically using dpm:
try {
Runtime.getRuntime().exec("dpm set-device-owner com.example.deviceowner/.MyDeviceAdminReceiver");
} catch (Exception e) {
Log.e(TAG, "device owner not set");
Log.e(TAG, e.toString());
e.printStackTrace();
}
Reference:
http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html
Trying to make my application device owner in simulator
I figured out the problem: I had given the package name wrong
correct format is:
admins-MacBook-Pro:platform-tools devrath$ ./adb shell dpm set-device-owner com.cnx.silentupdate/.DevAdminReceiver
Related Topics
Playing an Arbitrary Tone With Android
How to Parse the Androidmanifest.Xml File Inside an .Apk Package
How to Use Scrollview in Android
Android Get Free Size of Internal/External Memory
How to Implement a Custom Alertdialog View
How to Enable Logcat/Console in Eclipse For Android
Push Notifications in Android Platform
Getcolor(Int Id) Deprecated on Android 6.0 Marshmallow (API 23)
Context.Startforegroundservice() Did Not Then Call Service.Startforeground()
How to Programmatically Tell If a Bluetooth Device Is Connected
How to Hide Soft Keyboard on Android After Clicking Outside Edittext
Animate Change of View Background Color on Android
How to Develop a Soft Keyboard For Android