android 触发AppWidget上控件事件来更新AppWidget
2011-08-18 10:30
441 查看
思想:利用AppWidgetProvider里面的onReceive()事件接收广播来更新AppWidget。
步骤:
一、给AppWidget上的某个控件设置OnClickPendingIntent():
Intent UPintent=new Intent("zyf.test.widget.UP");
PendingIntent pendingIntentUp=PendingIntent.getBroadcast(context, 0, UPintent, 0);
views.setOnClickPendingIntent(R.id.widget_BT_Up, pendingIntentUp);
Intent UPintent=new Intent("zyf.test.widget.UP");
PendingIntent pendingIntentUp=PendingIntent.getBroadcast(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>
<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")){
//处理
}
步骤:
一、给AppWidget上的某个控件设置OnClickPendingIntent():
Intent UPintent=new Intent("zyf.test.widget.UP");
PendingIntent pendingIntentUp=PendingIntent.getBroadcast(context, 0, UPintent, 0);
views.setOnClickPendingIntent(R.id.widget_BT_Up, pendingIntentUp);
Intent UPintent=new Intent("zyf.test.widget.UP");
PendingIntent pendingIntentUp=PendingIntent.getBroadcast(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>
<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")){
//处理
}
相关文章推荐
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- android appwidget 点击事件详解 多个控件多个按钮不同响应
- android Appwidget单击事件触发
- Android开发之接受来自Appwidget的广播、更新Appwidget控件的状态
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- android AppWidget的使用以及利用Service TimerTask实现widget的定时更新
- android 之 桌面的小控件AppWidget
- Android开发之创建App Widget和更新Widget内容
- ANDROID_MARS学习笔记_S02_006_APPWIDGET2_PendingIntent及RemoteViews实现widget绑定点击事件
- Android的Appwidget TextView中没有更新(Android Appwidget textview not updating)
- android学习记录(九)AppWidget桌面控件轻松实现
- ANDROID_MARS学习笔记_S02_006_APPWIDGET3_AppWidget发送广播及更新AppWidget
- Android popupWindow 点击外部消失,点击外部其他控件触发其他事件
- android launcher桌面数字时钟及appwidget更新问题
- 增加Android下spinner控件的点击下拉列表自动更新事件并实例应用--USB摄像头在spinner内下拉更新(二)
- android 桌面控件appwidget
- Android之appWidget按钮事件
- 【Android随记】-- AppWidget更新桌面内容
- Android Appwidget 之按钮事件