Android Live wallpaper Tutorial

Live Wallpapers are animated , interactive backgrounds for the Android home screen. A live wallpaper is similar to other Android applications and can use most of the same functionality.

How to create a live wallpaper

To create a live wallpaper, you need to create an XML file which describes your wallpaper. This file should contain a description of the application and can contain a preview and a link to a preference activity Activity which allow to customize the live wallpaper.

You also create a service which must extend the  WallpaperService   class. This class is the base class for all live wallpapers in the system. You must implement the  onCreateEngine()  method and return an object of type  android.service.wallpaper.WallpaperService.Engine . This objects handles the lifecycle events, animations and drawings of the wallpaper. The Engine class defines the life cycle methods, as for example onCreate(), onSurfaceCreated(), onVisibilityChanged(), onOffsetsChanged(), onTouchEvent() and onCommand().

The service requires the permission  android.permission.BIND_WALLPAPER  and must be registered via an intent-filter for the  android.service.wallpaper.WallpaperService  action.

You should also enter in the  AndroidManifest.xml  file of the application that your application uses the  android.software.live_wallpaper  feature. This will prevent that your wallpaper can be installed on devices which do not support live wallpapers. In this tutorial we will be creating a cube  which will rotate in 3D space. This can be set as live wallpaper from live wallpaper chooser.

Lets get started :

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details.

2. Now create file in res/xml/cube.xml. This will provide settings to android live wallpaper manager. For now we are not entering anything. It is just declaring a live wallpaper.

3. Next we have to update AndroidManifest.xml so that it can include cube.xml file. We also have to declare the service which will provide animated cube to display as wallpaper. Update file looks like this.

3. Create  CubeWallpaper.java  in your default package. This class do all the animation and construction of the cube.It extends  WallpaperService  which is responsible for showing a live wallpaper behind applications that would like to sit on top of it. CubeWallpaper host another class  CubeEngine  which extends the  Engine . This CubeEngine do all the dirty work where Engine super class provide all the callback methods which are used to handle the wallpaper drawing and interaction. Code of CubeWallpaper.java goes like this.

4. Now build and run project.
5. To set livewallpaper go to Launcher > Menu > Home Screen Wallpaper > Live Wallpaper > Cube Live Wallpaper and press set live wallpaper.

guru

Technology enthusiast. Loves to tinker with things. Always trying to create something wonderful using technology. Loves coding for Android, Raspberry pi, Arduino , Opencv and much more.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *