App Widgets are miniature application views that can be embedded
in other applications (such as the Home screen) and receive
periodic updates。
App Widgets 是一个桌面应用程序,像快捷方式一样,放在我们的桌面上,
他还可以为我们提供数据的更新,在不同的时刻展示一个不同的东西。
现在有很多 APP 应用上面都有桌面小工具,比如说我们用的比较多的墨迹天气。
每天都可以从官方同步今天的最天气情况,让使用者能够更加方便的使用我们
的应用,既然可以他有这么优秀的一个特点,为什么我们不在我们自己的 App
中使用他呢?
要使用它,我们首先得知道他是怎么用的。
To create an App Widget, you need the following:
AppWidgetProviderInfo
object
Describes the metadata for an App Widget, such as the App
Widget's layout, update frequency, and the
AppWidgetProvider class. This should be de&ned in XML.
AppWidgetProvider
class implementation
De&nes the basic methods that allow you to
programmatically interface with the App Widget, based on
broadcast events. Through it, you will receive broadcasts
when the App Widget is updated, enabled, disabled and
deleted.
官网文档上面说得很清楚, 要创建一个 App Widget,我们必须要做两个事情:第一,
AppWidgetProvider 的 描 述 信 息 , 比 如 说 他 的 Layout 。 第 二 , 就 是 我 们 自 己 的
AppWidgetProvider 的实现了,我们需要通过他才能更新我们自己的 AppWidget。
下面我们一起来完成一个简单的桌面应用程序。
(1)、我们在 res 目录下新建一个 xml 的文件目录,然后在创建一个 appwidget-provider 的