AppWidget使用方法
手机桌面小组件
public class AppWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d("MyAppWidgetProvider", "调用了onUpdate方法");
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remoteview);
remoteViews.setImageViewResource(R.id.image, R.drawable.ic2);
remoteViews.setTextViewText(R.id.text, "我是桌面小组件");
remoteViews.setOnClickPendingIntent(R.id.image, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);//用updateAppWidget来更新remoteViews的状态
}
}
定义一个类继承AppWidgetProvider重写onupdate方法
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"> <ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
自定义布局文件remoteView
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/remoteview"
android:minWidth="100dp"
android:minHeight="100dp"
android:updatePeriodMillis="86400000"> </appwidget-provider>
xml文件appwidget
<receiver android:name=".AppWidget">
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidget"/>
<!--name的值是固定的,只能是android.appwidget.provider-->
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/><!--必须得有这个action-->
</intent-filter>
</receiver>
配置文件声明appwidget,运行后手机添加桌面小组件,点击图片会进入Pendingintent的activity
AppWidget使用方法的更多相关文章
- android app widget 创建调用周期
1 ?Android widget 大小问题 2 ?RemoteViewService Android开发历程_15(AppWidget的使用) Appwidget就是手机应用中常常放在桌面(即hom ...
- javaSE27天复习总结
JAVA学习总结 2 第一天 2 1:计算机概述(了解) 2 (1)计算机 2 (2)计算机硬件 2 (3)计算机软件 2 (4)软件开发(理解) 2 (5) ...
- Android UI组件----AppWidget控件入门详解
Widget引入 我们可以把Widget理解成放置在桌面上的小组件(挂件),有了Widget,我们可以很方便地直接在桌面上进行各种操作,例如播放音乐. 当我们长按桌面时,可以看到Widget选项,如下 ...
- Android AppWidget
AppWidget不知道大家使用这个多不多,这个在手机上也叫做挂件,挂件也就是放在桌面方便用户进行使用的,从android1.6开始挂件支持一些简单的lauout和view,到了android4.0之 ...
- android 之 桌面的小控件AppWidget
AppWidget是创建的桌面窗口小控件,在这个小控件上允许我们进行一些操作(这个视自己的需要而定).作为菜鸟,我在这里将介绍一下AppWeight的简单使用. 1.在介绍AppWidget之前,我们 ...
- Android实现AppWidget、Broadcast静态注册
Android实现AppWidget.Broadcast静态注册 本篇博客是基于我上一篇博客继续修改的,详情请看Android实现AppWidget.Broadcast动态注册 开发工具:Andori ...
- AppWidget框架
AppWidget 框架主要包括以下类: 1.AppWidgetProvider:继承自BroadcastReceiver,在AppWidget应用update.enable.disable和dele ...
- Android之桌面组件AppWidget
转载:Android之桌面组件App Widget初探 Android开发应用除了程序应用,还有App Widget应用.好多人会开发程序应用而不会开发App Widget应用.本帖子就是帮助大家学习 ...
- ANDROID_MARS学习笔记_S02_006_APPWIDGET3_AppWidget发送广播及更新AppWidget
一.简介 二.代码1.xml(1)example_appwidget.xml <?xml version="1.0" encoding="utf-8"?& ...
随机推荐
- Linux安装指定版Git以及卸载
来自于:https://www.cnblogs.com/rstyro/articles/10817855.html 安装Git 在linux中,安装Git 一般一条命令即可,如下: Debian/U ...
- 刷题[GXYCTF2019]禁止套娃
梳理思路 打开网站,发现很简单,只有flag在哪里的字样. 查看源码,常用后台目录,robots.txt,都未发现有任何东西. 扫描 直接拉进扫描器一扫,发现 思考可能是git源码泄露,可能可以恢复源 ...
- python协程(yield、asyncio标准库、gevent第三方)、异步的实现
引言 同步:不同程序单元为了完成某个任务,在执行过程中需靠某种通信方式以协调一致,称这些程序单元是同步执行的. 例如购物系统中更新商品库存,需要用"行锁"作为通信信号,让不同的更新 ...
- 交互平台 - Processing - 开发模板(仿Openframeworks)
之前在CSDN上发表过: https://blog.csdn.net/fddxsyf123/article/details/62425251
- Redis报错“ OOM command not allowed when used memory > 'maxmemory' ”
生产环境上遇到这个问题,控制台不停打印 "OOM command not allowed when used memory > 'maxmemory' "; 起初不知道是什么 ...
- 使用Flutter完成10个商业项目后的经验教训
作者:Łukasz Kosman 和 Jakub Wojtczak 原文:https://medium.com/swlh/lessons-learned-after-making-the-first- ...
- Django新手图文入门教程
版权所有,转载需注明来源! 本文是广受大家欢迎的<Django1.10新手图文入门教程>的2.1版本升级篇,原1.10版本传送门点击我 本文面向有一些的Python基础,但刚接触web框架 ...
- 利用mindmaster思维导图学好Python
- VS2013 c++ 生成和调用DLL动态链接库(.def 方法已验证OK)
转载:https://blog.csdn.net/zhunianguo/article/details/52294339 .def 方法 创建动态库方法: 创建动态库是生成 .dll .lib 两个个 ...
- JavaScript倒计时效果
实现思路: 输入的时间减去现在的时间就是剩余的时间,但是不能拿着时分秒相减,比如05分减去25分,结果会是负的. 可以用时间戳来做,用户输入时间总的毫秒数减去现在时间的总的毫秒数,得到的就是剩余时间的 ...