[英]How to update widget manually?
I want to update widget manually. 我想手动更新小部件。 So, I add in an AndroidManifest filter: 因此,我添加了一个AndroidManifest过滤器:
<action android:name="com.myapp.WIDGET_UPDATE"/>
And I try to send broadcasts from adb console like this 我尝试从这样的adb控制台发送广播
am broadcast -a com.myapp.WIDGET_UPDATE
But nothing happens. 但是什么也没发生。 Here is the code from onReceive: 这是onReceive的代码:
public class myapp extends AppWidgetProvider {
private final static IntentFilter intentFilter = new IntentFilter("com.myapp.WIDGET_UPDATE");
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
updateWidget(context);
}
};
}
you have to put one button in layout_wid.xml file. 您必须在layout_wid.xml文件中放置一个按钮。
in onUpdate()
you have to find the id of your button.and put click event to refresh your widget 在onUpdate()
您必须找到按钮的ID。并放置click事件以刷新小部件
Intent imageview2Intent= new Intent(context, WatchWidget.class);
PendingIntent pendingIntent= PendingIntent.getBroadcast(context,0, imageview2Intent,0);
remoteViews.setOnClickPendingIntent(R.id.widget_textview, pendingIntent);
you try this way. 您可以这样尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.