Search code examples
androidandroid-appwidgetonupdateandroid-remoteview

Android PedingIntent and setOnClickFillInIntent don't start Activity


In my AppsSerive i load the installed packages with:

mApps = mContext.getPackageManager().queryIntentActivities(mainIntent, 0);

then i show an icon of the application and the label. I want to start the activity after klick on the icon or label.

I have set a pendingIntentTemplate in my WidgetProvider in onUpdate:

 Intent appsIntent = new Intent(context, AppsService.class);
   String packageName = appsIntent.getStringExtra(APP_ID);
   appsIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
   PendingIntent appsPendingIntent = PendingIntent.getActivity(context, 0, appsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   views.setPendingIntentTemplate(R.id.GridViewApps, appsPendingIntent); 

And in the AppsService i have declared the setOnClickFillInIntent:

 Intent fillInIntent = new Intent();
    fillInIntent.setPackage(packageName);
    Bundle extras = new Bundle();
    fillInIntent.putExtras(extras);
    fillInIntent.addCategory(Intent.CATEGORY_DEFAULT);
    rv.setOnClickFillInIntent(R.id.app_thumb, fillInIntent);
    rv.setOnClickFillInIntent(R.id.app_name, fillInIntent);

But when i click on the icon or label, it dosn't do anything.

The LogCat shows at any click on it the following:

07-24 11:51:06.153: E/DatabaseUtils(16583): Writing exception to parcel
07-24 11:51:06.153: E/DatabaseUtils(16583): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
07-24 11:51:06.153: E/DatabaseUtils(16583):     at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14643)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2469)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:688)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at android.os.Binder.execTransact(Binder.java:404)
07-24 11:51:06.153: E/DatabaseUtils(16583):     at dalvik.system.NativeStart.run(Native Method)


07-24 11:51:06.384: W/ActivityManager(16583): destPackageName = null

Solution

  • I have identified three potential sources of the problem:

    1. You need to update your AppWidgetManager with updateAppWidget(...); after setting the click listeners

    2. I am not sure if you are using setOnClickFillInIntent() correctly. Are you using it intentionally and do you know what it does? You only really need it if your widget contains a collection like a ListView. If it doesn't use setOnClickPendingIntent().

    3. Could the error be here: fillInIntent.setPackage(packageName);? I think packageName might be null!