问题描述
我升级到最新的SDK和所有的突然我的小部件在启动时没有与此消息后回来的Widget开发
I got back to the widget development after upgrading to the latest SDK and all of the sudden my widget is failing on startup with this message:
ERROR/AndroidRuntime(5296): java.lang.RuntimeException:
Unable to start receiver topjob.widget.SearchWidget:
java.lang.SecurityException: Permission Denial:
attempt to change component state from pid=5296, uid=10057, package uid=10048
下面是code两线,其中发生异常:
Here's two lines of code where exception occurs:
@Override
public void onEnabled(Context context) {
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(new ComponentName("topjob",
".widget.SearchWidgetBroadcastReceiver"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
startAlarm(context, UPDATE_RATE_SEC);
}
所以在code以上 startAlarm()
,因为 pm.setComponentEnabledSetting永远不会执行()
抛出在SecurityException异常
so in the code above startAlarm()
is never executed since pm.setComponentEnabledSetting()
throws the SecurityException
我失去了我的清单任何安全设置?目前,我有:
Am I missing any security settings in my manifest? Currently I have:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
我制定 SDK诉1.5
并用它做工精细
P.S。它发生在手机上和模拟器
P.S. It happens on the phone and the emulator
推荐答案
确定 - 这是没有真正回答,而是一种解决方法。如果有人想介入,并提供解答或解释上应如何做我很乐意接受的。
反正 - 我把它从 COMPONENT_ENABLED_STATE_ENABLED
更改 newState
标志 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT 工作code>。由于我的广播接收器已在清单中启用状态只是正常工作
OK - this is not really answer but rather a workaround. If someone wants to step in and provide answer or explanations on how this should be done I would gladly accept that.Anyway - I got it working by changing newState
flag from COMPONENT_ENABLED_STATE_ENABLED
to PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
. Since my broadcast receiver has enabled state in the manifest it works just fine
这篇关于Android的 - 不能启用广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!