我想用DevicePolicyManager方法:setSecureSetting.此方法需要profil或设备所有者:
由配置文件或设备所有者调用以更新Settings.Secure设置.
我的应用程序已激活设备管理员,因为当我调用isAdminActive它时返回true.
但是当我打电话时setSecureSetting我得到了例外:
E/DevicePolicyUtility( 9901): java.lang.SecurityException: Admin ComponentInfo{com.xxxx/com.xxxx.MyDeviceAdminReceiver} does not own the profile
E/DevicePolicyUtility( 9901): at android.os.Parcel.readException(Parcel.java:1546)
E/DevicePolicyUtility( 9901): at android.os.Parcel.readException(Parcel.java:1499)
E/DevicePolicyUtility( 9901): at android.app.admin.IDevicePolicyManager$Stub$Proxy.setSecureSetting(IDevicePolicyManager.java:4300)
E/DevicePolicyUtility( 9901): at android.app.admin.DevicePolicyManager.setSecureSetting(DevicePolicyManager.java:3399)
Run Code Online (Sandbox Code Playgroud)
那么,如何成为API的设备所有者?我没有在http://developer.android.com/guide/topics/admin/device-admin.html或http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html中找到
我在API Level 23上尝试这个:
Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,ctx.getPackageName());
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(intent);
} else {
Toast.makeText(ctx, "Stopping.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
要成为设备所有者,有两种可能性
或者通过命令行,使用dpm如下工具:
亚行外壳
dpm 设置设备所有者 com.mycompany.deviceowner/.DeviceAdminReceiver
dpm set-device-owner:将给定组件设置为活动管理员,并将其包设置为设备所有者。
感谢弗洛伦特·杜邦:http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html
| 归档时间: |
|
| 查看次数: |
4369 次 |
| 最近记录: |