MG112
MG112

Reputation: 65

Start Activity from RemoteViewsFactory

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?

Upvotes: 1

Views: 334

Answers (1)

Xaver Kapeller
Xaver Kapeller

Reputation: 49817

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

Upvotes: 2

Related Questions