Use this snippet in onUpdate()
method of your widget AppWidgetProvider
class:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetlayout);
Intent configIntent = new Intent(context, Activity.class);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.widget, configPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
Here widgetlayout
is name of your widget layout and R.id.widget
is it's parent layout id.
Edit:
Now,I see your code that you added to your question.You would to do:
PendingIntent.getActivity(context, 0, configIntent, 0);
(that start's activity) instead of
PendingIntent.getService(...);
that attempt to starts service.Good luck.
References:
doityourselfandroid.com
helloandroid.com
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…