Skip to content

Instantly share code, notes, and snippets.

@sonianand11
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonianand11/d789ca9e405783e3515e to your computer and use it in GitHub Desktop.
Save sonianand11/d789ca9e405783e3515e to your computer and use it in GitHub Desktop.
package com.healthseva.widget;
import com.healthseva.R;
import com.healthseva.services.RandomTipService;
import com.healthseva.utility.ServiceUtility;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class MyWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
ServiceUtility.startService(context);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.health_seva_widget);
// remoteViews.setOnClickPendingIntent(R.id.widget_button, buildButtonPendingIntent(context));
System.out.println("widget Updated");
pushWidgetUpdate(context, remoteViews);
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.health_seva_widget);
// remoteViews.setOnClickPendingIntent(R.id.widget_button, buildButtonPendingIntent(context));
System.out.println("widget onDeleted");
ServiceUtility.stopService(context);
pushWidgetUpdate(context, remoteViews);
}
public static PendingIntent buildButtonPendingIntent(Context context) {
Intent intent = new Intent();
intent.setAction("pl.looksok.intent.action.CHANGE_PICTURE");
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) {
ComponentName myWidget = new ComponentName(context, HealthSevaWidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myWidget, remoteViews);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment