我有一个启动完整的广播接收器,但它没有按预期工作。全屏活动也不需要STATUS_BAR权限。
我试图在手机启动时查看LogCat日志,这就是我发现的:
LOG
04-11 14:23:48.718: W/PackageManager(133): Not granting permission
android.permission.BIND_DEVICE_ADMIN to package com.myprojects.myapp (protectionLevel=2 flags=0xbe46)
有什么理由会发生这种情况?
我的清单文件有:
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>
<receiver android:name="com.myprojects.myapp.DeviceAdministrationReceiver"
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>
<receiver android:name="com.myprojects.myapp.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
修改 和其他两个类似的日志:
04-11 14:24:17.810: W/PackageManager(133): Not granting permission android.permission.STATUS_BAR to package com.myprojects.myapp (protectionLevel=3 flags=0xbe46)
04-11 14:24:17.810: W/PackageManager(133): Not granting permission android.permission.WRITE_SECURE_SETTINGS to package com.myprojects.myapp (protectionLevel=3 flags=0xbe46)
答案 0 :(得分:1)
如果您是扩展DeviceAdminReceiver
,那么必须为接收器添加元数据和 description ,如下所示:
<receiver
android:name=".AdminReceiver"
android:description="@string/description"
android:label="@string/labelValue"
android:permission="android.permission.BIND_DEVICE_ADMIN"
>
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/lockourscreen"/>
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
{p} BIND_DEVICE_ADMIN
doc说:
Must be required by device administration receiver, to ensure that only the system can interact with it.
所以从应用程序级别删除<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>
行