1

i have an app launcher in an appwidget. I would to start Activitys from RemoteViewsFactory. But it didn't work.

Here is my Code from the RemoteViewsFactory:

@Override
public RemoteViews getViewAt(int position) {

    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.app_item);

    ResolveInfo info = mApps.get(position);
    Bundle extras = new Bundle();

    extras.putString(TheWidgetProvider.APP_ID, info.getClass().getName());
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.app_name, fillInIntent);

    return rv;

}

And here is my Code from the TheWidgetProvider:

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {


       Intent AppsServiceIntent = new Intent(context, AppsService.class);
       AppsServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
       AppsServiceIntent.setData(Uri.parse(AppsServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));
       views.setRemoteAdapter(R.id.GridViewApps, AppsServiceIntent);

       Intent appsIntent = new Intent(context, TheWidgetProvider.class);
       appsIntent.setAction(TheWidgetProvider.EVENT_SHOW_APP);
       appsIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
       appsIntent.setData(Uri.parse(updateServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));
       PendingIntent appsPendingIntent = PendingIntent.getBroadcast(context, 0, appsIntent,
               PendingIntent.FLAG_UPDATE_CURRENT);
       views.setPendingIntentTemplate(R.id.GridViewApps, appsPendingIntent);  

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

Have anyone an idea, why it doesn't work?

MG112
  • 55
  • 1
  • 8
  • What exactly are you trying to do? This exception means that you are doing something which requires the permission `INTERACT_ACROSS_USERS_FULL` but your app doesn't have this permission. In fact you **cannot** ever have this permission. It is a signature level permission and only Googles or the OEM Apps can ever have signature level permissions. So you are trying to do something which is off limits to normal developers. Anyway this is a completely different problem. It would be much better if you ask a new question about this problem. – Xaver Kapeller Jul 24 '14 at 10:17
  • Just accept my answer here if it solved the original issue with the `PendingIntents` and ask a new question about the new issue. You can basically just copy the lower part of this question to the new one. I would be happy to help you out with the new issue too so just post a link to the new question here in the comments and I will take a look. – Xaver Kapeller Jul 24 '14 at 10:19
  • I don't want anything do with these permission. I want only start an activity from an appwidget. My App shows a List with installed Packages and if an user will klick on one of the installed apps, the selected app shall open it. – MG112 Jul 24 '14 at 10:24
  • Well you are doing something which you are not supposed to. Just ask a new question about that and I'm sure we'll find a solution. Questions on Stack Overflow are supposed to only be about one problem. This one was about the issue with the `PendingIntents`, for this new issue it would be appropriate if you asked a new question. – Xaver Kapeller Jul 24 '14 at 10:26

1 Answers1

2

The error is here:

PendingIntent appsPendingIntent = PendingIntent.getBroadcast(context, 0, appsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent.getBroadcast(...) creates a broadcast, you need to use PendingIntent.getActivity(...) like this:

PendingIntent appsPendingIntent = PendingIntent.getActivity(context, 0, appsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
  • Thank You Xaver, i modified my Code, but it doesn't work too. On My WidgetProvider:` 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); ` `code in backticks`, – MG112 Jul 24 '14 at 09:56
  • Hi Xaver, correct. How i can show the Code in a comment? – MG112 Jul 24 '14 at 09:58
  • Comments are not supposed to be used for code. Edit your questions instead! – Xaver Kapeller Jul 24 '14 at 10:01
  • But just for reference, you can make a code block in the comments with backticks! Like this but without the spaces next to the backticks: ` Code goes here `. You can find more information about the markup used on Stack Overflow [**here**](http://meta.stackoverflow.com/editing-help). – Xaver Kapeller Jul 24 '14 at 10:03