android之app widget(三)
2012-03-14 15:29
477 查看
1. 接受来自App Widget的广播
//Androidmanifest中的文件旨要,只要有个一action符合就会调用继承AppWidgetProvider的类:
<receiver android:name="继承AppWidgetProvider的类">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATA"/>
</intent-filter>
<intent-filter>
<action android:name="mars.appwidget03.UPDATE_APP_WIDGET"/> //这是自定义action
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/example_appwidget_info"/>
</receiver>
//在代码中继承AppWidgetProvider的类的程况如下:
A. 在Update方法中
Intent intent = new Intent();
intent.setAction("mars.appwidget03.UPDATE_APP_WIDGET");
使用getBroadcast方法得到PendingIntent对象
PendingIntent pendingIntent = PendingIntent.getBroadcast(contect,0,intent对象,0);
B. 再onReciever方法中接收步骤A发送的广播
2. 更新App Widget当中控件的状态
public void onReceive(Context context, Intent intent){
String action = intent.getAction();
if(action == "mars.appwidget03.UPDATE_APP_WIDGET"){
RemoteViews remoteViews = new RemoteViews(context.getPackage , R.layout.example_appwidget);
//修改图片
remoteViews .setImageViewResource(R.id.imageId , R.drawable.ku);
remoteViews 。setTextViewText(R.id.widgetTextId , "");
//获得AppWidgetManager 对象
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
//ComponentName指的是整个app widget控件 , 而RemoteViews指的是app widget里面的控件
ComponentName componentName = new ComponentName(context, ExampleAppWidgetProvider.class);
//更新appwidget
appWidgetManager .updateAppWidget(componentName , remoteViews);
}
//必须要有else语句,不然其他的onUpdate,onEnable等函数将不会调用
else{
super onReceive(context,intent);
}
}
//Androidmanifest中的文件旨要,只要有个一action符合就会调用继承AppWidgetProvider的类:
<receiver android:name="继承AppWidgetProvider的类">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATA"/>
</intent-filter>
<intent-filter>
<action android:name="mars.appwidget03.UPDATE_APP_WIDGET"/> //这是自定义action
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/example_appwidget_info"/>
</receiver>
//在代码中继承AppWidgetProvider的类的程况如下:
A. 在Update方法中
Intent intent = new Intent();
intent.setAction("mars.appwidget03.UPDATE_APP_WIDGET");
使用getBroadcast方法得到PendingIntent对象
PendingIntent pendingIntent = PendingIntent.getBroadcast(contect,0,intent对象,0);
B. 再onReciever方法中接收步骤A发送的广播
2. 更新App Widget当中控件的状态
public void onReceive(Context context, Intent intent){
String action = intent.getAction();
if(action == "mars.appwidget03.UPDATE_APP_WIDGET"){
RemoteViews remoteViews = new RemoteViews(context.getPackage , R.layout.example_appwidget);
//修改图片
remoteViews .setImageViewResource(R.id.imageId , R.drawable.ku);
remoteViews 。setTextViewText(R.id.widgetTextId , "");
//获得AppWidgetManager 对象
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
//ComponentName指的是整个app widget控件 , 而RemoteViews指的是app widget里面的控件
ComponentName componentName = new ComponentName(context, ExampleAppWidgetProvider.class);
//更新appwidget
appWidgetManager .updateAppWidget(componentName , remoteViews);
}
//必须要有else语句,不然其他的onUpdate,onEnable等函数将不会调用
else{
super onReceive(context,intent);
}
}
相关文章推荐
- 为什么我的 app:actionViewClass="android.widget.SearchView"和app:showAsAction="ifRoom|collapseActionView"才有
- Android -- AppWidget 初级篇
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- Android --- App Widget 开发
- Android 之窗口小部件高级篇--App Widget 之 RemoteViews
- Android中的AppWidget
- Android AppWidget核心之AppWidgetService
- Android学习之AppWidget高级效果
- Android桌面小部件AppWidget:音乐播放器桌面控制部件Widget(3)
- Android实现AppWidget、Broadcast静态注册
- Android中实现Launcher功能之二 ----- 添加窗口小部件以及AppWidget的创建详解
- android appwidget 开发
- android 中 AppWidget 的 ListView 的实现
- Android---快速拨话程序(涵盖appWidget、Tab、联系人、多线程、自定义ListView使用)
- android桌面组件AppWidget
- android app widget,安卓桌面小工具的使用
- Android 之窗口小部件高级篇--App Widget 之 RemoteViews
- android 考研appwidget的实现
- Android中的AppWidget入门教程
- Android AppWidget的分析与应用AppWidgetProvider