In this exercise, a dummy home screen app widget will be described; to show the simpliest element of a ndroid app widget.

- Create a new project of ndroid application as normal, HelloWidget.
- Modify AndroidManifest.xml to have a receiver, with name of "HelloWidgetProvider", under Appliation.
element requires the android:name attribute, which specifies the AppWidgetProvider used by the App Widget.
The element must include an element with the android:name attribute. This attribute specifies that the AppWidgetProvider accepts the ACTION_APPWIDGET_UPDATE broadcast.
The element specifies the AppWidgetProviderInfo resource and requires the following attributes:
* android:name - Specifies the metadata name. Use android.appwidget.provider to identify the data as the AppWidgetProviderInfo descriptor.
* android:resource - Specifies the AppWidgetProviderInfo resource location.
- Create a new folder /res/xml, create a new hellowidgetproviderinfo.xml
, include the essential qualities of an App Widget, such as its minimum layout dimensions, its initial layout resource, how often to update the App Widget, and (optionally) a configuration Activity to launch at create-time.
- Create a layout file /res/layout/hellowidget_layout.xml
- Create a class HelloWidgetProvider.java extends AppWidgetProvider. With nothing inside.
Now you can build and Install the application as normal, then close it after started. It's not own target in this exercise.
- Add the HelloWidget on Home Screen, as describe in article "Home Screen App Widget". It's a dummy widget without any function, just show how to create a app widget.
Download the files.
Related Article:
minimum android:updatePeriodMillis
A simple Home Screen App Widget to get Date/Time

- Create a new project of ndroid application as normal, HelloWidget.
- Modify AndroidManifest.xml to have a receiver, with name of "HelloWidgetProvider", under Appliation.
package="com.exercise.HelloWidget"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name">
android:resource="@xml/hellowidgetproviderinfo" />
The The
The
* android:name - Specifies the metadata name. Use android.appwidget.provider to identify the data as the AppWidgetProviderInfo descriptor.
* android:resource - Specifies the AppWidgetProviderInfo resource location.
- Create a new folder /res/xml, create a new hellowidgetproviderinfo.xml
android:minWidth="146dp"
android:minHeight="72dp"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/hellowidget_layout"
>
It define the AppWidgetProviderInfo object in an XML resource using a single - Create a layout file /res/layout/hellowidget_layout.xml
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
It's the layout of the widget. In this dummy exercisse, just copy the content of the auto-generated layout, main.xml.- Create a class HelloWidgetProvider.java extends AppWidgetProvider. With nothing inside.
package com.exercise.HelloWidget;
import android.appwidget.AppWidgetProvider;
public class HelloWidgetProvider extends AppWidgetProvider {
}
It do nothing at all.Now you can build and Install the application as normal, then close it after started. It's not own target in this exercise.
- Add the HelloWidget on Home Screen, as describe in article "Home Screen App Widget". It's a dummy widget without any function, just show how to create a app widget.
Related Article:
minimum android:updatePeriodMillis
A simple Home Screen App Widget to get Date/Time