public class

WallpaperManager

extends Object
java.lang.Object
   ↳ android.app.WallpaperManager

Class Overview

Provides access to the system wallpaper. With WallpaperManager, you can get the current wallpaper, get the desired dimensions for the wallpaper, set the wallpaper, and more. Get an instance of WallpaperManager with getInstance().

Summary

Constants
String ACTION_LIVE_WALLPAPER_CHOOSER Launch an activity for the user to pick the current global live wallpaper.
String COMMAND_DROP Command for sendWallpaperCommand(IBinder, String, int, int, int, Bundle): reported by the wallpaper host when the user drops an object into an area of the host.
String COMMAND_TAP Command for sendWallpaperCommand(IBinder, String, int, int, int, Bundle): reported by the wallpaper host when the user taps on an empty area (not performing an action in the host).
Public Methods
void clear()
Remove any currently set wallpaper, reverting to the system's default wallpaper.
void clearWallpaperOffsets(IBinder windowToken)
Clear the offsets previously associated with this window through setWallpaperOffsets(IBinder, float, float).
int getDesiredMinimumHeight()
Returns the desired minimum height for the wallpaper.
int getDesiredMinimumWidth()
Returns the desired minimum width for the wallpaper.
Drawable getDrawable()
Retrieve the current system wallpaper; if no wallpaper is set, the system default wallpaper is returned.
Drawable getFastDrawable()
Like getDrawable(), but the returned Drawable has a number of limitations to reduce its overhead as much as possible.
static WallpaperManager getInstance(Context context)
Retrieve a WallpaperManager associated with the given Context.
WallpaperInfo getWallpaperInfo()
If the current wallpaper is a live wallpaper component, return the information about that wallpaper.
Drawable peekDrawable()
Retrieve the current system wallpaper; if there is no wallpaper set, a null pointer is returned.
Drawable peekFastDrawable()
Like getFastDrawable(), but if there is no wallpaper set, a null pointer is returned.
void sendWallpaperCommand(IBinder windowToken, String action, int x, int y, int z, Bundle extras)
Send an arbitrary command to the current active wallpaper.
void setBitmap(Bitmap bitmap)
Change the current system wallpaper to a bitmap.
void setResource(int resid)
Change the current system wallpaper to the bitmap in the given resource.
void setStream(InputStream data)
Change the current system wallpaper to a specific byte stream.
void setWallpaperOffsetSteps(float xStep, float yStep)
For applications that use multiple virtual screens showing a wallpaper, specify the step size between virtual screens.
void setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset)
Set the position of the current wallpaper within any larger space, when that wallpaper is visible behind the given window.
void suggestDesiredDimensions(int minimumWidth, int minimumHeight)
For use only by the current home application, to specify the size of wallpaper it would like to use.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_LIVE_WALLPAPER_CHOOSER

Since: API Level 7

Launch an activity for the user to pick the current global live wallpaper.

Constant Value: "android.service.wallpaper.LIVE_WALLPAPER_CHOOSER"

public static final String COMMAND_DROP

Since: API Level 7

Command for sendWallpaperCommand(IBinder, String, int, int, int, Bundle): reported by the wallpaper host when the user drops an object into an area of the host. The x and y arguments are the location of the drop.

Constant Value: "android.home.drop"

public static final String COMMAND_TAP

Since: API Level 7

Command for sendWallpaperCommand(IBinder, String, int, int, int, Bundle): reported by the wallpaper host when the user taps on an empty area (not performing an action in the host). The x and y arguments are the location of the tap in screen coordinates.

Constant Value: "android.wallpaper.tap"

Public Methods

public void clear ()

Since: API Level 5

Remove any currently set wallpaper, reverting to the system's default wallpaper. On success, the intent ACTION_WALLPAPER_CHANGED is broadcast.

Throws
IOException If an error occurs reverting to the default wallpaper.

public void clearWallpaperOffsets (IBinder windowToken)

Since: API Level 5

Clear the offsets previously associated with this window through setWallpaperOffsets(IBinder, float, float). This reverts the window to its default state, where it does not cause the wallpaper to scroll from whatever its last offsets were.

Parameters
windowToken The window who these offsets should be associated with, as returned by View.getWindowToken().

public int getDesiredMinimumHeight ()

Since: API Level 5

Returns the desired minimum height for the wallpaper. Callers of setBitmap(android.graphics.Bitmap) or setStream(java.io.InputStream) should check this value beforehand to make sure the supplied wallpaper respects the desired minimum height. If the returned value is <= 0, the caller should use the height of the default display instead.

Returns
  • The desired minimum height for the wallpaper. This value should be honored by applications that set the wallpaper but it is not mandatory.

public int getDesiredMinimumWidth ()

Since: API Level 5

Returns the desired minimum width for the wallpaper. Callers of setBitmap(android.graphics.Bitmap) or setStream(java.io.InputStream) should check this value beforehand to make sure the supplied wallpaper respects the desired minimum width. If the returned value is <= 0, the caller should use the width of the default display instead.

Returns
  • The desired minimum width for the wallpaper. This value should be honored by applications that set the wallpaper but it is not mandatory.

public Drawable getDrawable ()

Since: API Level 5

Retrieve the current system wallpaper; if no wallpaper is set, the system default wallpaper is returned. This is returned as an abstract Drawable that you can install in a View to display whatever wallpaper the user has currently set.

Returns
  • Returns a Drawable object that will draw the wallpaper.

public Drawable getFastDrawable ()

Since: API Level 5

Like getDrawable(), but the returned Drawable has a number of limitations to reduce its overhead as much as possible. It will never scale the wallpaper (only centering it if the requested bounds do match the bitmap bounds, which should not be typical), doesn't allow setting an alpha, color filter, or other attributes, etc. The bounds of the returned drawable will be initialized to the same bounds as the wallpaper, so normally you will not need to touch it. The drawable also assumes that it will be used in a context running in the same density as the screen (not in density compatibility mode).

Returns
  • Returns a Drawable object that will draw the wallpaper.

public static WallpaperManager getInstance (Context context)

Since: API Level 5

Retrieve a WallpaperManager associated with the given Context.

public WallpaperInfo getWallpaperInfo ()

Since: API Level 7

If the current wallpaper is a live wallpaper component, return the information about that wallpaper. Otherwise, if it is a static image, simply return null.

public Drawable peekDrawable ()

Since: API Level 5

Retrieve the current system wallpaper; if there is no wallpaper set, a null pointer is returned. This is returned as an abstract Drawable that you can install in a View to display whatever wallpaper the user has currently set.

Returns
  • Returns a Drawable object that will draw the wallpaper or a null pointer if these is none.

public Drawable peekFastDrawable ()

Since: API Level 5

Like getFastDrawable(), but if there is no wallpaper set, a null pointer is returned.

Returns
  • Returns an optimized Drawable object that will draw the wallpaper or a null pointer if these is none.

public void sendWallpaperCommand (IBinder windowToken, String action, int x, int y, int z, Bundle extras)

Since: API Level 7

Send an arbitrary command to the current active wallpaper.

Parameters
windowToken The window who these offsets should be associated with, as returned by View.getWindowToken().
action Name of the command to perform. This must be a scoped name to avoid collisions, such as "com.mycompany.wallpaper.DOIT".
x Arbitrary integer argument based on command.
y Arbitrary integer argument based on command.
z Arbitrary integer argument based on command.
extras Optional additional information for the command, or null.

public void setBitmap (Bitmap bitmap)

Since: API Level 5

Change the current system wallpaper to a bitmap. The given bitmap is converted to a PNG and stored as the wallpaper. On success, the intent ACTION_WALLPAPER_CHANGED is broadcast.

Parameters
bitmap The bitmap to save.
Throws
IOException If an error occurs reverting to the default wallpaper.

public void setResource (int resid)

Since: API Level 5

Change the current system wallpaper to the bitmap in the given resource. The resource is opened as a raw data stream and copied into the wallpaper; it must be a valid PNG or JPEG image. On success, the intent ACTION_WALLPAPER_CHANGED is broadcast.

Parameters
resid The bitmap to save.
Throws
IOException If an error occurs reverting to the default wallpaper.

public void setStream (InputStream data)

Since: API Level 5

Change the current system wallpaper to a specific byte stream. The give InputStream is copied into persistent storage and will now be used as the wallpaper. Currently it must be either a JPEG or PNG image. On success, the intent ACTION_WALLPAPER_CHANGED is broadcast.

Parameters
data A stream containing the raw data to install as a wallpaper.
Throws
IOException If an error occurs reverting to the default wallpaper.

public void setWallpaperOffsetSteps (float xStep, float yStep)

Since: API Level 7

For applications that use multiple virtual screens showing a wallpaper, specify the step size between virtual screens. For example, if the launcher has 3 virtual screens, it would specify an xStep of 0.5, since the X offset for those screens are 0.0, 0.5 and 1.0

Parameters
xStep The X offset delta from one screen to the next one
yStep The Y offset delta from one screen to the next one

public void setWallpaperOffsets (IBinder windowToken, float xOffset, float yOffset)

Since: API Level 5

Set the position of the current wallpaper within any larger space, when that wallpaper is visible behind the given window. The X and Y offsets are floating point numbers ranging from 0 to 1, representing where the wallpaper should be positioned within the screen space. These only make sense when the wallpaper is larger than the screen.

Parameters
windowToken The window who these offsets should be associated with, as returned by View.getWindowToken().
xOffset The offset along the X dimension, from 0 to 1.
yOffset The offset along the Y dimension, from 0 to 1.

public void suggestDesiredDimensions (int minimumWidth, int minimumHeight)

Since: API Level 5

For use only by the current home application, to specify the size of wallpaper it would like to use. This allows such applications to have a virtual wallpaper that is larger than the physical screen, matching the size of their workspace.

Parameters
minimumWidth Desired minimum width
minimumHeight Desired minimum height