page.title=Live Wallpapers @jd:body

See also

  1. Live Wallpaper sample

Starting with Android 2.1 (API Level 7), users can now enjoy live wallpapers — richer, animated, interactive backgrounds — on their home screens. A live wallpaper is very similar to a normal Android application and has access to all the facilities of the platform: SGL (2D drawing), OpenGL (3D drawing), GPS, accelerometers, network access, etc. The live wallpapers included on Nexus One demonstrate the use of some of these APIs to create fun and interesting user experiences. For instance, the Grass wallpaper uses the phone's location to compute sunrise and sunset times in order to display the appropriate sky.

Creating your own live wallpaper is easy, especially if you have had previous experience with SurfaceView or Canvas. To learn how to create a live wallpaper, you should check out the CubeLiveWallpaper sample code.

In terms of implementation, a live wallpaper is very similar to a regular Android service. The only difference is the addition of a new method, {@code onCreateEngine()}, whose goal is to create a WallpaperService.Engine. The engine is responsible for handling the lifecycle and drawing of a wallpaper. The system provides a surface on which you can draw, just like you would with a SurfaceView. Drawing a wallpaper can be very expensive so you should optimize your code as much as possible to avoid using too much CPU, not only for battery life but also to avoid slowing down the rest of the system. That is also why the most important part of the lifecycle of a wallpaper is when it becomes invisible. When invisible, such as when the user launches an application that covers the home screen, a wallpaper must stop all activity.

The engine can also implement several methods to interact with the user or the home application. For instance, if you want your wallpaper to scroll along when the user swipes from one home screen to another, you can use onOffsetsChanged(). To react to touch events, simply implement onTouchEvent(MotionEvent). Finally, applications can send arbitrary commands to the live wallpaper. Currently, only the standard home application sends commands to the onCommand() method of the live wallpaper:

If you are developing a live wallpaper, remember that the feature is supported only on Android 2.1 (API level 7) and higher versions of the platform. To ensure that your application can only be installed on devices that support live wallpapers, remember to add the following to the application's manifest before publishing to Android Market:

Many great live wallpapers are already available on Android Market and we can't wait to see more!