Last active
December 10, 2016 19:43
-
-
Save yerenutku/aefda7f82d4a895d0189cd397961d828 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
public class SimpleAppWidget extends AppWidgetProvider { | |
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
// There may be multiple widgets active, so update all of them | |
for (int appWidgetId : appWidgetIds) { | |
updateAppWidget(context, appWidgetManager, appWidgetId); | |
} | |
} | |
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, | |
int appWidgetId) { | |
// Construct the RemoteViews object | |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.simple_app_widget); | |
// Construct an Intent object includes web adresss. | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://erenutku.com")); | |
// In widget we are not allowing to use intents as usually. We have to use PendingIntent instead of 'startActivity' | |
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | |
// Here the basic operations the remote view can do. | |
views.setOnClickPendingIntent(R.id.tvWidget, pendingIntent); | |
// Instruct the widget manager to update the widget | |
appWidgetManager.updateAppWidget(appWidgetId, views); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment