本文介绍了是否有可能抛出意向APPWIDGET_UPDATE编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想一个按钮,在我的小部件火APPWIDGET_UPDATE意图上的小部件类来强制更新,但我没有看到APPWIDGET_UPDATE作为意向静态字段。
这是可能的,以及如何将一个做到这一点?
意向意图=新的意图(背景下,BaseWidgetProvider.class);
intent.setAction({APPWIDGET_UPDATE意图HERE})
PendingIntent pendingIntent = PendingIntent.getActivity(上下文,0,意图,0);
views.setOnClickPendingIntent(R.id.MyWidgetButton,pendingIntent);
解决方案
是,这是可能的。你会发现在动作 AppWidgetManager
:
编辑:您需要提供您要更新的小部件的ID。下面是一个完整的样本。
AppWidgetManager widgetManager = AppWidgetManager.getInstance(上下文);
组件名widgetComponent =新的组件名(背景下,YourWidget.class);
INT [] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
意向更新=新意图();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
context.sendBroadcast(更新);
Would like a button in my widget to fire the APPWIDGET_UPDATE intent on the widget class to force an update, but I dont see APPWIDGET_UPDATE as a static field in Intent.
Is this possible, and how would one do this?
Intent intent = new Intent(context, BaseWidgetProvider.class);
intent.setAction({APPWIDGET_UPDATE INTENT HERE})
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.MyWidgetButton, pendingIntent);
解决方案
Yes, it's possible. You'll find the action in AppWidgetManager
:
Edit: You will need to provide the ids of the widgets you want to update. Below is a complete sample.
AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
ComponentName widgetComponent = new ComponentName(context, YourWidget.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
context.sendBroadcast(update);
这篇关于是否有可能抛出意向APPWIDGET_UPDATE编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!