运行意图DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN从服务 [英] Run intent DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN from a service
问题描述
我有一个服务,我要服务促进使其能够为设备管理员, 到现在为止我公司推出这种UI交互从服务像
I have a service and I want the service promote to enable it as Device Admin, until now I launched this kind of UI interactions from the service like
Intent intent2 = new Intent();
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent2.setAction(android.content.Intent.ACTION_VIEW);
intent2.setDataAndType(uri, "application/vnd.android.package-archive");
context.startActivity(intent2);
和它的工作原理,但与DevicePolicyManager我找不到的方式:
and it works, but with DevicePolicyManager I can't find the way:
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "some text.");
context.startActivity(intent);
简化版,工作方式:不提倡什么,但也不会崩溃。如果没有 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
这只是崩溃,因为这code是一个服务里面的胎面内。想法?
does't work: do not promote nothing but also do not crash. Without intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
It simply crash because this code is inside a tread inside a service. Ideas?
推荐答案
我刚刚固定等问题,为我自己。
I've just fixed such issue for myself.
请注意,你需要把这个code里面父的Android Manifest.xml文件:
Note, that you need to put this code inside parent in Android Manifest.xml file:
<receiver
android:name=".ScreenLockerDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_policies" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
和它的工作原理:)
这篇关于运行意图DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN从服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!