2016年8月11日 星期四

How to update the widget?

48 How to update the widget?

send the brodcast,the widget provider run onUpdate

Intent broadcastIntent=new Intent();
       broadcastIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
       sendBroadcast(broadcastIntent);

       AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
       int[] ids = widgetManager.getAppWidgetIds(new ComponentName(this, AppWidgettatic.class));
       broadcastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
       sendBroadcast(broadcastIntent);