Question

Je suis revenu au développement du widget après la mise à niveau du dernier SDK et tout à coup, mon widget échoue au démarrage avec ce 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

Voici deux lignes de code où l'exception se produit:

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

Donc dans le code ci-dessus startAlarm() n'est jamais exécuté depuis pm.setComponentEnabledSetting() lance le SecurityException

Est-ce que je manque des paramètres de sécurité dans mon manifeste? Actuellement, j'ai:

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

Je développe pour SDK v. 1.5 Et ça fonctionnait bien

PS Cela se produit sur le téléphone et l'émulateur

Était-ce utile?

La solution 3

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

Autres conseils

Sur le manifeste.xml vous ajouterez

<permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
android:sharedUserId="android.uid.system"

Sur Android.mk ajoutera

LOCAL_CERTIFICATE := platform  

C'est tout.

Can you try adding this permission in your manifest?

<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>

I only got this error "java.lang.SecurityException: Permission Denial: " when I try to disable some component out of the package it is running in.Otherwise, I got success.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top