public class WallpaperController extends Object
SystemCapability.Miscservices#WALLPAPER| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
WALLPAPER_LOCK |
Indicates the lock screen wallpaper.
|
static int |
WALLPAPER_SYSTEM |
Indicates the home screen wallpaper.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
WallpaperColorsCollection |
getColors(int wallpaperType) |
Obtains the
WallpaperColorsCollection instance for the wallpaper of the specified type. |
Element |
getDefaultElement(int outWidth,
int outHeight,
boolean scaleToFit,
float horizontalAlignment,
float verticalAlignment,
int wallpaperType) |
Obtains the
Element instance of the default built-in static wallpaper. |
Element |
getElement() |
Obtains the
Element instance of the current system wallpaper. |
FileDescriptor |
getFile(int wallpaperType) |
Obtains a file descriptor to the wallpaper of the specified type.
|
int |
getId(int wallpaperType) |
Obtains the ID of the wallpaper of the specified type.
|
static WallpaperController |
getInstance(Context context) |
Obtains a
WallpaperController instance. |
int |
getMinHeight() |
Obtains the minimum height of the wallpaper.
|
int |
getMinWidth() |
Obtains the minimum width of the wallpaper.
|
boolean |
isChangePermitted() |
Checks whether to allow the application to change the wallpaper for the current user.
|
boolean |
isOperationAllowed() |
Checks whether a user is allowed to set wallpapers.
|
void |
registerColorsChangedListener(IWallpaperColorsChangedListener listener) |
Registers a listener for wallpaper color changes to receive notifications about the changes.
|
void |
reset(int wallpaperType) |
Removes a wallpaper of the specified type and restores the default one.
|
void |
setPadding(Rect padding) |
Sets wallpaper padding that exceeds the display area.
|
void |
setWallpaper(InputStream inputStream,
int wallpaperType) |
Sets a wallpaper of the specified type based on the data stream from a JPEG or PNG file.
|
void |
setWallpaper(PixelMap pixelMap,
int wallpaperType) |
Sets a wallpaper of the specified type based on the pixel map of a PNG file.
|
void |
unregisterColorsChangedListener(IWallpaperColorsChangedListener listener) |
Unregisters a listener for wallpaper color changes.
|
public static final int WALLPAPER_LOCK
public static final int WALLPAPER_SYSTEM
public static WallpaperController getInstance(Context context)
WallpaperController instance.context - Indicates the application context.
If this parameter is invalid, your application cannot access the wallpaper management service.WallpaperController instance.public void registerColorsChangedListener(IWallpaperColorsChangedListener listener)
listener - Indicates the listener for wallpaper color changes.
The caller can customize follow-up operations when your application is notified of the changes.public void unregisterColorsChangedListener(IWallpaperColorsChangedListener listener)
listener - Indicates the listener to unregister.public int getMinHeight()
WallpaperController#setWallpaper(PixelMap, int) and
WallpaperController#setWallpaper(InputStream, int).0 if no wallpaper has been set. In this case,
you should use the default height.public int getMinWidth()
WallpaperController#setWallpaper(PixelMap, int) and
WallpaperController#setWallpaper(InputStream, int).0 if no wallpaper has been set. In this case,
you should use the default width.public boolean isChangePermitted()
true if the application is allowed to set a wallpaper for the current user;
returns false otherwise.public boolean isOperationAllowed()
true if a user is allowed to set wallpapers; returns false otherwise.public int getId(int wallpaperType)
The ID of a wallpaper changes each time the wallpaper is set. You can call this method to know whether the wallpaper has changed.
wallpaperType - Indicates the type of the wallpaper whose ID will be returned.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.0 representing the wallpaper ID
if the specified type of wallpaper has been set; returns -1 otherwise.
The return value is an integer ranging from -1 to 2^31 - 1.public void setWallpaper(PixelMap pixelMap, int wallpaperType)
SystemPermission#SET_WALLPAPER permission.pixelMap - Indicates the pixel map of the PNG file.wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.public void setWallpaper(InputStream inputStream, int wallpaperType)
SystemPermission#SET_WALLPAPER permission.inputStream - Indicates the data stream from a JPEG or PNG file.wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.public FileDescriptor getFile(int wallpaperType)
Calling this method requires the SystemPermission#GET_WALLPAPER and
SystemPermission#READ_USER_STORAGE permissions.
wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.null if no wallpaper of the specified type is set,
or the application does not have the permission to access the wallpaper.public void reset(int wallpaperType)
Calling this method requires the SystemPermission#SET_WALLPAPER permission.
wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.public void setPadding(Rect padding)
Calling this method requires the SystemPermission#SET_WALLPAPER_DIMENSION permission.
padding - Indicates the number of additional pixels outside of the display on
left, right, top, and bottom sides of the wallpaper.public WallpaperColorsCollection getColors(int wallpaperType)
WallpaperColorsCollection instance for the wallpaper of the specified type.wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.WallpaperColorsCollection instance if any; returns null if a color is
unknown.public Element getDefaultElement(int outWidth, int outHeight, boolean scaleToFit, float horizontalAlignment, float verticalAlignment, int wallpaperType)
Element instance of the default built-in static wallpaper.outWidth - Indicates the width of the Element instance.outHeight - Indicates the height of the Element instance.scaleToFit - Specifies whether the wallpaper can be scaled.
Value true indicates that the wallpaper can be scaled and cropped to fit the screen,
and false indicates that the wallpaper can be cropped only.horizontalAlignment - Indicates the horizontal alignment mode.
The value ranges from 0 to 1.
Value 0 indicates left alignment, 0.5 indicates center alignment,
and 1 indicates right alignment.verticalAlignment - Indicates the vertical alignment mode. The value ranges from 0 to 1.
Value 0 indicates top alignment, 0.5 indicates center alignment,
and 1 indicates bottom alignment.wallpaperType - Indicates the wallpaper type.
The value can be WALLPAPER_SYSTEM or WALLPAPER_LOCK.Element instance of the default built-in static wallpaper.public Element getElement()
Element instance of the current system wallpaper.Element instance of the current system wallpaper;
returns the default built-in static wallpaper if no wallpaper is set;
returns null if any of the following occurs: