手机桌面小组件

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使用方法的更多相关文章

  1. android app widget 创建调用周期

    1 ?Android widget 大小问题 2 ?RemoteViewService Android开发历程_15(AppWidget的使用) Appwidget就是手机应用中常常放在桌面(即hom ...

  2. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  3. Android UI组件----AppWidget控件入门详解

    Widget引入 我们可以把Widget理解成放置在桌面上的小组件(挂件),有了Widget,我们可以很方便地直接在桌面上进行各种操作,例如播放音乐. 当我们长按桌面时,可以看到Widget选项,如下 ...

  4. Android AppWidget

    AppWidget不知道大家使用这个多不多,这个在手机上也叫做挂件,挂件也就是放在桌面方便用户进行使用的,从android1.6开始挂件支持一些简单的lauout和view,到了android4.0之 ...

  5. android 之 桌面的小控件AppWidget

    AppWidget是创建的桌面窗口小控件,在这个小控件上允许我们进行一些操作(这个视自己的需要而定).作为菜鸟,我在这里将介绍一下AppWeight的简单使用. 1.在介绍AppWidget之前,我们 ...

  6. Android实现AppWidget、Broadcast静态注册

    Android实现AppWidget.Broadcast静态注册 本篇博客是基于我上一篇博客继续修改的,详情请看Android实现AppWidget.Broadcast动态注册 开发工具:Andori ...

  7. AppWidget框架

    AppWidget 框架主要包括以下类: 1.AppWidgetProvider:继承自BroadcastReceiver,在AppWidget应用update.enable.disable和dele ...

  8. Android之桌面组件AppWidget

    转载:Android之桌面组件App Widget初探 Android开发应用除了程序应用,还有App Widget应用.好多人会开发程序应用而不会开发App Widget应用.本帖子就是帮助大家学习 ...

  9. ANDROID_MARS学习笔记_S02_006_APPWIDGET3_AppWidget发送广播及更新AppWidget

    一.简介 二.代码1.xml(1)example_appwidget.xml <?xml version="1.0" encoding="utf-8"?& ...

随机推荐

  1. Spring Boot实战之Redis缓存登录验证码

    1.工具类 1 import lombok.experimental.UtilityClass; 2 3 import java.awt.*; 4 import java.awt.image.Buff ...

  2. 吴恩达-机器学习+正则化regularization

  3. 提权 EXP

    windows: 漏洞列表 #Security Bulletin #KB #Description #Operating System CVE-2017-0213 [Windows COM Eleva ...

  4. JS中的DOM对象

    DOM对象 1. DOM树 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model),通过 HTML DOM对象,可访问 JavaScript HTML 文档的所有 ...

  5. 再玩树莓派(二)Jexus&.NetCore

    接上一篇,操作系统弄好之后,轮到开发运行环境的搭建. 先说说目标,也就是我到底想搞什么飞机.先说说小目标吧. 现有一个手机App客户端,以答题小游戏作为其内容(例如:口算题,24点,科学百科等) 树莓 ...

  6. 【字符串算法】AC自动机

    国庆后面两天划水,甚至想接着发出咕咕咕的叫声.咳咳咳,这些都不重要!最近学习了一下AC自动机,发现其实远没有想象中的那么难. AC自动机的来历 我知道,很多人在第一次看到这个东西的时侯是非常兴奋的.( ...

  7. 011 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 05 变量的三个元素的详细介绍之三—— 变量值——即Java中的“字面值”

    011 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 05 变量的三个元素的详细介绍之三-- 变量值--即Java中的"字面值" 变量值可以是 ...

  8. lens distortion

    来源:http://michel.thoby.free.fr/Fisheye_history_short/International_Standards_about_Distortion.html H ...

  9. devops-jenkins基于角色的权限管理RBAC

    一. devops-jenkins基于角色的权限管理RBAC 1 安装角色的rbac角色管理  1.1) 点击系统管理 1.2) 选择插件管理 1.3) 选择可选插件,输入role搜索 1.4) 选择 ...

  10. Github个人首页美化指北

    当你尝试去创建一个与你Github用户名相同的仓库时,会发现这是Github为你预留的特殊仓库,用来作为你的Github Profile,这个仓库就相当于一个可以显示在你Github个人页的READM ...