String action = intent.getAction();
Log.d(TAG, "intent=" + intent);
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
Log.d(TAG, "ENABLED");
}
else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
Log.d(TAG, "DISABLED");
}
else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
Log.d(TAG, "UPDATE");
// BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
Bundle extras = intent.getExtras();
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
// END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
SharedPreferences prefs = context.getSharedPreferences(
TestAppWidgetProvider.PREFS_NAME, 0);
String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
AppWidgetManager gm = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
if (false) {
gm.updateAppWidget(appWidgetIds, views);
} else {
gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost",
"com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
}
}