Last active
August 29, 2015 14:04
-
-
Save sonianand11/d789ca9e405783e3515e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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