android手机deviceowner,android - How to make my app a device owner? - Stack Overflow

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

usage: dpm set-profile-owner

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值