Reputation: 1
I was using the Guardian news app and noticed that their widget had an options button that opened anther menu. I am not sure how this is done. If anyone has any ideas that would great.
Upvotes: 0
Views: 25
Reputation: 3732
You can send an Intent
as usual:
public class YourWidget extends AppWidgetProvider {
static PendingIntent getPendingSelfIntent(Context context, String action, int appWidgetId) {
KLog.d(TAG, "getPendingSelfIntent appWidgetId = " + appWidgetId);
Intent intent = new Intent(context, YourWidget.class);
Bundle b = new Bundle();
b.putInt("appWidgetId", appWidgetId);
intent.putExtras(b);
intent.setAction(action);
PendingIntent pendInt = PendingIntent.getBroadcast(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return pendInt;
}
//....
//your method for remote views
public void doUpdateView() {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.collection_widget);
remoteViews.setOnClickPendingIntent(R.id.button_settings, getPendingSelfIntent(context, RUN_CLICKED, appWidgetId));
}
@Override
public void onReceive(final Context context, Intent intent) {
super.onReceive(context, intent);
if (RUN_CLICKED.equals(intent.getAction())) {
Intent actIntent = new Intent(context, YourActivity.class);
actIntent.putExtra("your_extra_key", your_extra_value);
actIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(actIntent);
}
//...
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
Upvotes: 0