O'Reilly logo

Learning Android, 2nd Edition by Masumi Nakamura, Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. Interaction and Animation: Live Wallpaper and Handlers

This chapter covers the animated LiveWallpaper API that allows developers to create interactive wallpaper that users may choose to run as part of their home page. We also cover handlers, an essential part of the Android thread system that enhances interactivity.

Live Wallpaper

Android 2.1 (API Level 7) introduced live wallpaper. A live wallpaper is a wallpaper (a background set on the home screen) that may be animated and enabled for interaction. It has access to the other services and APIs as normal Android applications: network, GPS, etc. The primary class to use when creating a live wallpaper is the LiveWallpaperService (located in android.service.wallpaper.WallpaperService).

For an example, we will put together a live wallpaper that is touch-enabled and utilizes the Internet (via the Yamba Manager) in order to place some text at the point of touch. To do this, you must add a service definition within the main Manifest (see Example 16-1). Next, create a Service Resource (see Example 16-2).

Example 16-1. LiveWallpaper Service Manifest entry
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.marakana.android.yamba">

    <application>

        <service
            android:label="@string/app_name"
            android:icon="@drawable/ic_launcher"
            android:name=".YambaWallpaper"
            android:permission="android.permission.BIND_WALLPAPER">
            <intent-filter>
              <action
                android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required