android 触发AppWidget上控件事件来更新AppWidget
来源:互联网 发布:浅猪家的七七知乎 编辑:程序博客网 时间:2024/06/04 21:52
思想:利用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")){
//处理
}
- android 触发AppWidget上控件事件来更新AppWidget
- 触发AppWidget上控件事件来更新AppWidget
- android 桌面控件appwidget
- Android中的AppWidget(上)
- Android中的AppWidget(上)
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- Android开发之接受来自Appwidget的广播、更新Appwidget控件的状态
- Android Appwidget 之按钮事件
- Android之appWidget按钮事件
- Android appWidget支持的控件
- Android:AppWidget 桌面小控件
- Appwidget
- AppWidget
- AppWidget
- appwidget
- Appwidget
- AppWidget
- servlet的定义及其生命周期
- Hive源码解析—之—Hive的入口
- Commons BeanUtils 中对Map的操作
- Linux tar命令详解与打包
- java基础问题----Integer与int的区别
- android 触发AppWidget上控件事件来更新AppWidget
- Subversion客户端认证缓存问题
- android 让Activity单例运行
- 一行另linux死机的命令
- JS操作JSON总结
- android实现应用程序无图标(快捷方式)问题
- Asp.net MVC学习日记五(自定义RouteHandler)
- C#序列化技术详解(转)
- C/C++ 库函数 二分查找 bsearch