final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class);
resultIntent.putExtra("actionFromUser", true);
resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- // resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK );
// From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId));
resultIntent.setData(data);
PendingIntent.FLAG_UPDATE_CURRENT
);
remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent);
-// final PendingIntent resultPendingIntent = PendingIntent.getActivity(
-// this.getApplicationContext(),
-// 0,
-// resultIntent,
-// PendingIntent.FLAG_UPDATE_CURRENT);
-// remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent);
return remoteView;
}
final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class);
resultIntent.putExtra("actionFromUser", true);
resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
-// resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK );
// From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId));
resultIntent.setData(data);
PendingIntent.FLAG_UPDATE_CURRENT
);
remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent);
-// final PendingIntent resultPendingIntent = PendingIntent.getActivity(
-// this.getApplicationContext(),
-// 0,
-// resultIntent,
-// PendingIntent.FLAG_UPDATE_CURRENT);
-// remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent);
return remoteView;
}
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
-import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.os.Bundle;
public class WidgetProvider extends AppWidgetProvider {
}
public static void updateAppWidget(final Context context, final int appWidgetId) {
- final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());
-
- updateAppWidget(context, appWidgetManager, appWidgetId);
- }
- public static void refreshAppWidget(final Context context, final int appWidgetId) {
- final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());
-
- refreshAppWidget(context.getApplicationContext(), appWidgetManager, appWidgetId);
+ final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+ intent.putExtra("refreshAppWidget", false);
+ context.startService(intent);
}
public static void refreshAllAppWidgets(final Context context) {
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widgets);
for (final int appWidgetId : appWidgetIds) {
- refreshAppWidget(context.getApplicationContext(), appWidgetManager, appWidgetId);
+ refreshAppWidget(context.getApplicationContext(), appWidgetId);
}
}
- private static void refreshAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
-
- int widgetId;
- Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
-
- // Get the value of OPTION_APPWIDGET_HOST_CATEGORY
- int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1);
-
- // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget
- boolean isKeyguard = category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
-
- // Once you know the widget's category, you can optionally load a different base layout, set different
- // properties, and so on. For example:
- //int baseLayout = isKeyguard ? R.layout.keyguard_widget_layout : R.layout.widget_layout;
-
- // Construct the RemoteViews object. It takes the package name (in our case, it's our
- // package, but it needs this because on the other side it's the widget host inflating
- // the layout from our package).
- //final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
+ public static void refreshAppWidget(final Context context, final int appWidgetId) {
final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.putExtra("refreshAppWidget", true);
context.startService(intent);
}
-
- private static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
-
- int widgetId;
- Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
-
- // Get the value of OPTION_APPWIDGET_HOST_CATEGORY
- int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1);
-
- // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget
- boolean isKeyguard = category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
-
- // Once you know the widget's category, you can optionally load a different base layout, set different
- // properties, and so on. For example:
- //int baseLayout = isKeyguard ? R.layout.keyguard_widget_layout : R.layout.widget_layout;
-
- // Construct the RemoteViews object. It takes the package name (in our case, it's our
- // package, but it needs this because on the other side it's the widget host inflating
- // the layout from our package).
- //final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
-
- final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- intent.putExtra("refreshAppWidget", false);
- context.startService(intent);
- }
}