Configuring the Android Manifest File for App Widgets
Certainly, there are simpler ways to update your App Widget. For example, the App Widget could use its one service to do all the work of downloading the threat level data and updating the App Widget content, but then the application is left to do its own thing.The method described here illustrates how you can bypass some of the update frequency limitations of App Widgets and still share content between App Widgets and their underlying application. Tip Updating the RemoteViews object need not happen from within the App Widget provider. It can be called directly from the application, too. In this example, the service created for downloading the threat level data is used by the application and App Widget alike. Using a service for downloading online data is a good practice for a number of reasons. However, if there was no download service to leverage, we could have gotten away with just one service. In this service, fully controlled by the App Widget, we would have not only done the download but also then updated the RemoteViews object directly. Doing this would have eliminated the need for listening to the shared preferences changes from the App Widget service, too.In order for the Android system to know about your application’s App Widget, you mustinclude a <receiver> tag in the application’s Android manifest file to register it as an App Widget provider.App Widgets often use services, and these services must be registered within the Android manifest file with a <service> tag like any other service. Here is an excerpt of the Android manifest file from the SimpleAppWidget.
Notice that, unlike a typical <receiver> definition, a <meta-data> section references an XML file resource.The <receiver> tag includes several bits of information about the App Widget configuration, including a label and icon for the App Widget, which is displayed on the App Widget picker (where the user chooses from available App Widgets on the system).The <receiver> tag also includes an intent filter to handle the android.appwidget.action.APPWIDGET_UPDATE intent action, as well as a <meta-data> tag that references the App Widget configuration file stored in the XML resource directory. Finally, the services used to update the App Widget are registered.
Installing an App Widget
After your application has implemented App Widget functionality, a user (who has installed your application) can install it to the Home screen using the following stepsAlthough somewhat less common, applications might also become App Widget hosts.App Widget hosts (android.appWidget.AppWidgetHost) are simply containers that can embed and display App Widgets.The most commonly used App Widget host is the Home screen. For more information on developing an App Widget host, see the Android SDK documentation.In addition to still image wallpapers,Android supports the notion of a live wallpaper. Instead of displaying a static background image on the Home screen, the user can set an interactive, or live,wallpaper that can display anything that can be drawn on a surface, such as graphics and animations. Live wallpapers were introduced in Android 2.1 (API Level 7). Your applications can provide live wallpapers that use 3D graphics and animations as well as display interesting application content. Some examples of live wallpapers include.
Creating a Live Wallpaper
A live wallpaper is similar to an Android Service, but its result is a surface that the host can display.You need to make the following changes to your application in order to support live wallpapers: n Provide an XML wallpaper configuration. n Provide a WallpaperService implementation.? n Update the application Android manifest file to register the wallpaper service with the appropriate permissions. Now let’s look at some of these requirements in greater detail.The guts of the live wallpaper functionality are provided as part of a WallpaperService implementation, and most of the live wallpaper functionality is driven by its WallpaperService.Engine implementation. Implementing a Wallpaper Service Your application needs to extend the WallpaperService class.The most important method the class needs to override is the onCreateEngine() method. Here is a sample implementation of a wallpaper service called SimpleDroidWallpaper: public class SimpleDroidWallpaper extends WallpaperService { private final Handler handler = new Handler.