1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| /**
* Implementation of App Widget functionality.
*/
public class NewAppWidget extends AppWidgetProvider
{
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId)
{
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
String T_Ext_Value2 = "26";
String H_Ext_Value2 = "53";
String A_Ext_Value2 = "212";
String Timer2 = "2019-07-06 14:13:20";
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
views.setTextViewText(R.id.appwidget_Text, T_Ext_Value2);
views.setTextViewText(R.id.appwidget_Hext, H_Ext_Value2);
views.setTextViewText(R.id.appwidget_Aext, A_Ext_Value2);
views.setTextViewText(R.id.appwidget_Timestamp, Timer2);
views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@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);
}
}
@Override
public void onEnabled(Context context)
{
// Enter relevant functionality for when the first widget is created
}
@Override
public void onDisabled(Context context)
{
// Enter relevant functionality for when the last widget is disabled
}
} |
Partager