思想:利用AppWidgetProvider里面的onReceive()事件接收广播来更新AppWidget。
步骤:
一、给AppWidget上的某个控件设置OnClickPendingIntent():
二、设置AppWidget的intent-filter:
三、在onReceive()中判断;
注:附件是从eoeandroid上下载的
步骤:
一、给AppWidget上的某个控件设置OnClickPendingIntent():
Intent UPintent=new Intent("zyf.test.widget.UP");
PendingIntent pendingIntentUp=PendingIntent.[color=red]getBroadcast[/color](context, 0, UPintent, 0);
views.setOnClickPendingIntent(R.id.widget_BT_Up, pendingIntentUp);
二、设置AppWidget的intent-filter:
<receiver android:name="AppWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>
<action android:name="zyf.test.widget.UP"></action>
<action android:name="zyf.test.widget.DOWN"></action>
</intent-filter>
<meta-data android:resource="@xml/appwidget" android:name="android.appwidget.provider"></meta-data>
</receiver>
三、在onReceive()中判断;
super.onReceive(context, intent);
if(intent.getAction().equals("zyf.test.widget.UP")){
//处理
}
注:附件是从eoeandroid上下载的