I\'ve been working on a widget and making some advances (I hope) but still can\'t get it to do what I want.
I have a configurator activity which works ok. When it cl
You need to set a last flag in a getBroadcast: PendingIntent.FLAG_UPDATE_CURRENT
For Updating Your Home Screen widget on Touch You need to Register a custom broadcast receiver in Manifest and add it as action with widget as:
Step 1: Register Custom Receiver as:
<intent-filter>
<action android:name="com.imrankhanandroid.HomeWidgetRandomNum.ACTION_WIDGET_RANDOM"/>
</intent-filter>
Step 2: In Your Widget Class AddAction to layout as:
public void onReceive(Context paramContext, Intent paramIntent)
{
//Intent
String str = paramIntent.getAction();
if (paramIntent.getAction().equals(ACTION_WIDGET_RANDOM)) {
updateWidgetState(paramContext, str);
}
else
{
super.onReceive(paramContext, paramIntent);
}
}
STEP 3: In Your updateWidgetState add new action to Intent as:
rview = new RemoteViews(paramContext.getPackageName(), R.layout.widget_layoutmain);
Intent active = new Intent(paramContext, Randomnuberwidget.class);
active.setAction(ACTION_WIDGET_RANDOM);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(paramContext, 0, active, 0);
rview.setOnClickPendingIntent(R.id.ImageView_gps, actionPendingIntent);
Finally you can Download Working HomeWidget Example from HERE HomeWidgetRendomNumber Which Generating Random Number On Every Click.
In your function updateAppWidget
go to this line:
PendingIntent widgetPendingIntent = PendingIntent.getBroadcast(context, 0, widgetIntent, 0);
...and change it into:
PendingIntent widgetPendingIntent = PendingIntent.getBroadcast(context, appWidgetId, widgetIntent, 0);