1*90c8c64dSAndroid Build Coastguard Worker<p>This sample demonstrates how to create a live wallpaper and bundle it in an 2*90c8c64dSAndroid Build Coastguard Worker<code>.apk</code> that users can install on their devices.</p> 3*90c8c64dSAndroid Build Coastguard Worker 4*90c8c64dSAndroid Build Coastguard Worker<p>In terms of implementation, a live wallpaper is very similar to a regular 5*90c8c64dSAndroid Build Coastguard WorkerAndroid <a href="../../../reference/android/app/Service.html">service</a>. The 6*90c8c64dSAndroid Build Coastguard Workeronly difference is the addition of a new method, <a 7*90c8c64dSAndroid Build Coastguard Workerhref="../../../reference/android/service/wallpaper/WallpaperService.html#onCreateEngine()"><code> 8*90c8c64dSAndroid Build Coastguard WorkeronCreateEngine()</code></a>, whose goal is to 9*90c8c64dSAndroid Build Coastguard Workercreate a <a 10*90c8c64dSAndroid Build Coastguard Workerhref="../../../reference/android/service/wallpaper/WallpaperService.Engine.html"> 11*90c8c64dSAndroid Build Coastguard Worker<code>WallpaperService.Engine</code></a>. The engine is responsible for 12*90c8c64dSAndroid Build Coastguard Workerhandling the lifecycle and drawing of a wallpaper. The system provides a surface 13*90c8c64dSAndroid Build Coastguard Workeron which you can draw, just like you would with a <a 14*90c8c64dSAndroid Build Coastguard Workerhref="../../../reference/android/view/SurfaceView.html"><code>SurfaceView</code></a>. 15*90c8c64dSAndroid Build Coastguard WorkerThe wallpapers you create can respond to touch events on the screen and 16*90c8c64dSAndroid Build Coastguard Workerhave access to all the facilities of the platform: SGL (2D drawing), OpenGL (3D 17*90c8c64dSAndroid Build Coastguard Workerdrawing), GPS, accelerometers, network access, and so on. </p> 18*90c8c64dSAndroid Build Coastguard Worker 19*90c8c64dSAndroid Build Coastguard Worker<p>The examples in this application show how to set up a wallpaper service that 20*90c8c64dSAndroid Build Coastguard Workercreates a <code>WallpaperService.Engine</code> to manage the service lifecycle, 21*90c8c64dSAndroid Build Coastguard Workerrender the wallpaper, handle touch events, and so on. The examples also show how 22*90c8c64dSAndroid Build Coastguard Workera wallpaper should stop drawing when its visibility changes, for example, when 23*90c8c64dSAndroid Build Coastguard Workerthe user launches an application that covers the home screen. Drawing only when 24*90c8c64dSAndroid Build Coastguard Workervisible is an important implementation guideline for live wallpapers because it 25*90c8c64dSAndroid Build Coastguard Workerminimizes the wallpaper's impact on system performance and battery life. 26*90c8c64dSAndroid Build Coastguard Worker</p> 27*90c8c64dSAndroid Build Coastguard Worker 28*90c8c64dSAndroid Build Coastguard Worker<p>The application includes two wallpaper services and a wallpaper settings 29*90c8c64dSAndroid Build Coastguard Workeractivity:<p> 30*90c8c64dSAndroid Build Coastguard Worker 31*90c8c64dSAndroid Build Coastguard Worker<ul> 32*90c8c64dSAndroid Build Coastguard Worker<li><a 33*90c8c64dSAndroid Build Coastguard Workerhref="src/com/example/android/livecubes/cube1/CubeWallpaper1.html"><code> 34*90c8c64dSAndroid Build Coastguard WorkerCubeWallpaper1</code></a> — a wallpaper service that draws and animates a 35*90c8c64dSAndroid Build Coastguard Workerwire-frame cube to a <a 36*90c8c64dSAndroid Build Coastguard Workerhref="../../../reference/android/graphics/Canvas.html"><code>Canvas</code></a>. 37*90c8c64dSAndroid Build Coastguard Worker</li> 38*90c8c64dSAndroid Build Coastguard Worker<li><a 39*90c8c64dSAndroid Build Coastguard Workerhref="src/com/example/android/livecubes/cube2/CubeWallpaper2.html"><code>CubeWallpaper2</code></a> 40*90c8c64dSAndroid Build Coastguard Worker— a wallpaper service that draws and animates a 41*90c8c64dSAndroid Build Coastguard Workerwire-frame shape to a <code>Canvas</code>. The shape is set by the user, by means 42*90c8c64dSAndroid Build Coastguard Workerof the <code>cube2.CubeWallpaper2Settings</code> settings activity (see below). The 43*90c8c64dSAndroid Build Coastguard Workerwallpaper service implements a listener callback method that captures the user's 44*90c8c64dSAndroid Build Coastguard Workerwallpaper shape preference. </li> 45*90c8c64dSAndroid Build Coastguard Worker<li><a 46*90c8c64dSAndroid Build Coastguard Workerhref="src/com/example/android/livecubes/cube2/CubeWallpaper2Settings.html"><code>CubeWallpaper2Settings</code></a> 47*90c8c64dSAndroid Build Coastguard Worker— a wallpaper service that draws and 48*90c8c64dSAndroid Build Coastguard Workeranimates a wire-frame shape to a <code>Canvas</code>. The shape is set by the 49*90c8c64dSAndroid Build Coastguard Workeruser through a simple settings activity, 50*90c8c64dSAndroid Build Coastguard Worker<code>cube2.CubeWallpaper2Settings</code>, also included in the app. The 51*90c8c64dSAndroid Build Coastguard Workerwallpaper service implements a listener callback method that captures the user's 52*90c8c64dSAndroid Build Coastguard Workerwallpaper shape preference. </li> 53*90c8c64dSAndroid Build Coastguard Worker</ul> 54*90c8c64dSAndroid Build Coastguard Worker 55*90c8c64dSAndroid Build Coastguard Worker<p>If you are developing a live wallpaper, remember that the feature is 56*90c8c64dSAndroid Build Coastguard Workersupported only on Android 2.1 (API level 7) and higher versions of the platform. 57*90c8c64dSAndroid Build Coastguard WorkerTo ensure that your application can only be installed on devices that support 58*90c8c64dSAndroid Build Coastguard Workerlive wallpapers, remember to add the following to the application's manifest 59*90c8c64dSAndroid Build Coastguard Workerbefore publishing to Google Play:</p> 60*90c8c64dSAndroid Build Coastguard Worker 61*90c8c64dSAndroid Build Coastguard Worker<ul> 62*90c8c64dSAndroid Build Coastguard Worker<li><code><uses-sdk android:minSdkVersion="7" /></code>, which indicates 63*90c8c64dSAndroid Build Coastguard Workerto Google Play and the platform that your application requires Android 2.1 or 64*90c8c64dSAndroid Build Coastguard Workerhigher. For more information, see the <a href="../../../guide/appendix/api-levels.html">API Levels</a> 65*90c8c64dSAndroid Build Coastguard Workerand the documentation for the 66*90c8c64dSAndroid Build Coastguard Worker<a href="../../../guide/topics/manifest/uses-sdk-element.html"><code><uses-sdk></code></a> 67*90c8c64dSAndroid Build Coastguard Workerelement.</li> 68*90c8c64dSAndroid Build Coastguard Worker<li><code><uses-feature android:name="android.software.live_wallpaper" /></code>, 69*90c8c64dSAndroid Build Coastguard Workerwhich tells Google Play that your application includes a live wallpaper. 70*90c8c64dSAndroid Build Coastguard WorkerGoogle Play uses this feature as a filter, when presenting users lists of 71*90c8c64dSAndroid Build Coastguard Workeravailable applications. When you declaring this feature, Google Play 72*90c8c64dSAndroid Build Coastguard Workerdisplays your application only to users whose devices support live wallpapers, 73*90c8c64dSAndroid Build Coastguard Workerwhile hiding it from other devices on which it would not be able to run. For 74*90c8c64dSAndroid Build Coastguard Workermore information, see the documentation for the 75*90c8c64dSAndroid Build Coastguard Worker<a href="../../../guide/topics/manifest/uses-feature-element.html"><code><uses-feature></code></a> 76*90c8c64dSAndroid Build Coastguard Workerelement.</li> 77*90c8c64dSAndroid Build Coastguard Worker</ul> 78*90c8c64dSAndroid Build Coastguard Worker 79*90c8c64dSAndroid Build Coastguard Worker<p>For more information about live wallpapers, see the 80*90c8c64dSAndroid Build Coastguard Worker<a href="../../articles/live-wallpapers.html">Live Wallpapers</a> article. </p> 81*90c8c64dSAndroid Build Coastguard Worker 82*90c8c64dSAndroid Build Coastguard Worker<img alt="Screenshot 1" src="../images/CubeLiveWallpaper1.png" /> 83*90c8c64dSAndroid Build Coastguard Worker<img alt="Screenshot 3" src="../images/CubeLiveWallpaper3.png" /> 84