I want to update widget manually. So, I add in an AndroidManifest filter:
<action android:name="com.myapp.WIDGET_UPDATE"/>
And I try to send broadcasts from adb console like this
am broadcast -a com.myapp.WIDGET_UPDATE
But nothing happens. Here is the code from 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.
in onUpdate()
you have to find the id of your button.and put click event to refresh your widget
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.