views:

337

answers:

1

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

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);
}

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" />

I'm developing for SDK v. 1.5 and it used to work fine

P.S. It happens on the phone and the emulator

A: 

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

DroidIn.net