Android:AppWidget、桌面小部件
16lz
2021-01-26
主要事件方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /** * Implementation of App Widget functionality. */ public class NewAppWidget extends AppWidgetProvider { /** * 到达指定的更新时间或者当用户向桌面添加AppWidget时被调用 * */ @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int [] appWidgetIds) { // There may be multiple widgets active, so update all of them final int N = appWidgetIds.length; for ( int i = 0 ; i < N; i++) { updateAppWidget(context, appWidgetManager, appWidgetIds[i]); } } /** * AppWidget的实例第一次被创建时调用 * */ @Override public void onEnabled(Context context) { // Enter relevant functionality for when the first widget is created } /** * 最后一个appWidget被删除时调用 * */ @Override public void onDisabled(Context context) { // Enter relevant functionality for when the last widget is disabled } /** * 接受广播事件 * */ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub super .onReceive(context, intent); } /** * 删除一个AppWidget时调用 * */ @Override public void onDeleted(Context context, int [] appWidgetIds) { // TODO Auto-generated method stub super .onDeleted(context, appWidgetIds); } static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { CharSequence widgetText = context.getString(R.string.appwidget_text); // Construct the RemoteViews object RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); views.setTextViewText(R.id.appwidget_text, widgetText); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, views); } } |
本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1228549,如需转载请自行联系原作者
更多相关文章
- android Activity 之间传递复杂对象
- Android布局整理
- android ViewGroup删除子视图时应该注意的一个问题
- andriod一个不错的启动菜单显示屏动画效果
- 在ubuntu 14.04 编译android 2.3.1 错误解决办法
- Android(安卓)Matrix
- android 带清除功能的EditText
- android中短信协议与字段
- Ubuntu 12.04中Android(安卓)NDK r8d 编译 FFmpeg 0.11.1 并使用