Most visited

Recently visited

Added in API level 5

WallpaperManager

public class WallpaperManager
extends Object

java.lang.Object
   ↳ android.app.WallpaperManager


提供对系统壁纸的访问。 使用WallpaperManager,您可以获取当前壁纸,获取所需的壁纸尺寸,设置壁纸等等。 使用getInstance()获取WallpaperManager的实例。

应用程序可以通过调用 isWallpaperSupported()来检查当前用户是否支持壁纸,以及是否允许设置壁纸,方法是调用 isSetWallpaperAllowed()

Summary

Constants

String ACTION_CHANGE_LIVE_WALLPAPER

直接发布动态壁纸预览,允许用户立即确认切换到特定的动态壁纸。

String ACTION_CROP_AND_SET_WALLPAPER

活动操作:显示选择壁纸的设置。

String ACTION_LIVE_WALLPAPER_CHOOSER

为用户启动一个活动,以选择当前的全球动态壁纸。

String COMMAND_DROP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:当用户将对象放入主机区域时由壁纸主机报告。

String COMMAND_SECONDARY_TAP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:由用户在空白区域释放辅助指针(不在主机中执行操作)时由壁纸主机报告。

String COMMAND_TAP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:当用户点击空白区域(不在主机中执行动作)时由墙纸主机报告。

String EXTRA_LIVE_WALLPAPER_COMPONENT

ACTION_CHANGE_LIVE_WALLPAPER中额外指定应该显示为预览的动态壁纸的ComponentName,供用户确认。

int FLAG_LOCK

标志:设置或检索锁定屏幕特定的壁纸。

int FLAG_SYSTEM

标志:设置或检索一般系统壁纸。

String WALLPAPER_PREVIEW_META_DATA

ACTION_SET_WALLPAPER响应的活动的清单条目,允许他们提供与此操作关联的自定义大图标。

Public methods

void clear(int which)

删除一个或多个当前设置的壁纸,恢复到每个壁纸的系统默认显示。

void clear()

删除当前设置的系统壁纸,恢复到系统的内置壁纸。

void clearWallpaperOffsets(IBinder windowToken)

通过 setWallpaperOffsets(IBinder, float, float)清除先前与此窗口相关的偏移量。

void forgetLoadedWallpaper()

删除上次加载的壁纸的所有内部引用。

Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, float horizontalAlignment, float verticalAlignment, int which)

返回指定类型的内置静态壁纸的drawable。

Drawable getBuiltInDrawable(int which)

为指定的内置静态系统壁纸获取drawable。

Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, float horizontalAlignment, float verticalAlignment)

返回系统内置静态壁纸的drawable。

Drawable getBuiltInDrawable()

获取内置静态系统壁纸的drawable。

Intent getCropAndSetWallpaperIntent(Uri imageUri)

获取一个意图,该意图将启动裁剪给定图像并设置设备壁纸的活动。

int getDesiredMinimumHeight()

返回壁纸所需的最小高度。

int getDesiredMinimumWidth()

返回所需的墙纸最小宽度。

Drawable getDrawable()

检索当前的系统壁纸; 如果未设置壁纸,则返回系统内置静态壁纸。

Drawable getFastDrawable()

getDrawable()一样,但是返回的Drawable有很多限制来尽可能减少其开销。

static WallpaperManager getInstance(Context context)

检索与给定上下文关联的WallpaperManager。

ParcelFileDescriptor getWallpaperFile(int which)

获得一个开放的,可读的文件描述符到给定的壁纸图像文件。

int getWallpaperId(int which)

获取给定种类的当前壁纸的ID。

WallpaperInfo getWallpaperInfo()

如果当前壁纸是动态壁纸组件,则返回有关该壁纸的信息。

boolean hasResourceWallpaper(int resid)

返回是否有任何用户当前设置为使用具有给定资源ID的墙纸。

boolean isSetWallpaperAllowed()

返回是否允许调用包为主叫用户设置壁纸。

boolean isWallpaperSupported()

返回主叫用户是否支持壁纸。

Drawable peekDrawable()

检索当前的系统壁纸; 如果没有设置壁纸,则返回空指针。

Drawable peekFastDrawable()

getFastDrawable()一样,但是如果没有设置壁纸,则返回空指针。

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

发送任意命令到当前活动墙纸。

int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)

版本 setBitmap(Bitmap, Rect, boolean) ,允许调用者指定要设置哪些支持的壁纸类别。

void setBitmap(Bitmap bitmap)

将当前系统壁纸更改为位图。

int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup)

将当前系统壁纸更改为位图,指定关于完整图像的哪个子矩形可见的提示。

int setResource(int resid, int which)

版本 setResource(int) ,允许调用者指定要设置哪些支持的壁纸类别。

void setResource(int resid)

将当前系统墙纸更改为给定资源中的位图。

void setStream(InputStream bitmapData)

将当前系统壁纸更改为特定的字节流。

int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup, int which)

版本 setStream(InputStream, Rect, boolean) ,允许调用者指定要设置哪些支持的壁纸类别。

int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup)

将当前系统壁纸更改为特定的字节流,指定关于完整图像的哪个子矩形可见的提示。

void setWallpaperOffsetSteps(float xStep, float yStep)

对于使用多个虚拟屏幕显示壁纸的应用程序,指定虚拟屏幕之间的步长。

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

设置当前壁纸在任何较大空间内的显示位置,当该壁纸在给定窗口后面可见时。

void suggestDesiredDimensions(int minimumWidth, int minimumHeight)

仅供当前家庭应用程序使用,以指定要使用的壁纸大小。

Inherited methods

From class java.lang.Object

Constants

ACTION_CHANGE_LIVE_WALLPAPER

Added in API level 16
String ACTION_CHANGE_LIVE_WALLPAPER

直接发布动态壁纸预览,允许用户立即确认切换到特定的动态壁纸。 您必须使用要显示的动态墙纸组件的ComponentName指定EXTRA_LIVE_WALLPAPER_COMPONENT

常量值:“android.service.wallpaper.CHANGE_LIVE_WALLPAPER”

ACTION_CROP_AND_SET_WALLPAPER

Added in API level 19
String ACTION_CROP_AND_SET_WALLPAPER

活动操作:显示选择壁纸的设置。 不要直接用来构建一个意图; 而是使用getCropAndSetWallpaperIntent(Uri)

输入: getData()是要裁剪并设置为墙纸的图像的URI。

输出:如果用户决定裁剪/设置墙纸,RESULT_OK RESULT_CANCEL,否则支持此意图的活动应该指定一个MIME过滤器“image / *”

常量值:“android.service.wallpaper.CROP_AND_SET_WALLPAPER”

ACTION_LIVE_WALLPAPER_CHOOSER

Added in API level 7
String ACTION_LIVE_WALLPAPER_CHOOSER

为用户启动一个活动,以选择当前的全球动态壁纸。

常量值:“android.service.wallpaper.LIVE_WALLPAPER_CHOOSER”

COMMAND_DROP

Added in API level 7
String COMMAND_DROP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:当用户将对象放入主机区域时由壁纸主机报告。 x和y参数是放置的位置。

常量值:“android.home.drop”

COMMAND_SECONDARY_TAP

Added in API level 11
String COMMAND_SECONDARY_TAP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:当用户在空白区域释放辅助指针(未在主机中执行动作)时由壁纸主机报告。 x和y参数是屏幕坐标中辅助水龙头的位置。

常量值:“android.wallpaper.secondaryTap”

COMMAND_TAP

Added in API level 7
String COMMAND_TAP

sendWallpaperCommand(IBinder, String, int, int, int, Bundle)命令:当用户点击空白区域(未在主机中执行动作)时由壁纸主机报告。 x和y参数是屏幕坐标中水龙头的位置。

常量值:“android.wallpaper.tap”

EXTRA_LIVE_WALLPAPER_COMPONENT

Added in API level 16
String EXTRA_LIVE_WALLPAPER_COMPONENT

ACTION_CHANGE_LIVE_WALLPAPER中额外指定应显示为预览的动态壁纸的ComponentName,供用户确认。

常量值:“android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT”

FLAG_LOCK

Added in API level 24
int FLAG_LOCK

标志:设置或检索锁定屏幕特定的壁纸。

常量值:2(0x00000002)

FLAG_SYSTEM

Added in API level 24
int FLAG_SYSTEM

标志:设置或检索一般系统壁纸。

常数值:1(0x00000001)

WALLPAPER_PREVIEW_META_DATA

Added in API level 11
String WALLPAPER_PREVIEW_META_DATA

ACTION_SET_WALLPAPER作出响应的活动的清单条目,允许它们提供与此操作关联的自定义大图标。

常量值:“android.wallpaper.preview”

Public methods

clear

Added in API level 24
void clear (int which)

删除一个或多个当前设置的壁纸,恢复到每个壁纸的系统默认显示。 如果FLAG_SYSTEM在设定which参数,意图ACTION_WALLPAPER_CHANGED将在成功播出。

Parameters
which int: A bitwise combination of FLAG_SYSTEM or FLAG_LOCK
Throws
IOException If an error occurs reverting to the built-in wallpaper.

clear

Added in API level 5
void clear ()

删除当前设置的系统壁纸,恢复到系统的内置壁纸。 成功时,意向ACTION_WALLPAPER_CHANGED被广播。

此方法要求调用方拥有权限 SET_WALLPAPER

Throws
IOException If an error occurs reverting to the built-in wallpaper.

clearWallpaperOffsets

Added in API level 5
void clearWallpaperOffsets (IBinder windowToken)

通过setWallpaperOffsets(IBinder, float, float)清除先前与此窗口相关的偏移量。 这会将窗口恢复为默认状态,不会导致壁纸从上一次偏移量处滚动。

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

forgetLoadedWallpaper

Added in API level 14
void forgetLoadedWallpaper ()

删除上次加载的壁纸的所有内部引用。 对于希望减少内存使用量的应用程序非常有用,因为它们只是暂时需要壁纸。 在调用之后,壁纸的下一个请求将需要重新从磁盘重新加载。

getBuiltInDrawable

Added in API level 24
Drawable getBuiltInDrawable (int outWidth, 
                int outHeight, 
                boolean scaleToFit, 
                float horizontalAlignment, 
                float verticalAlignment, 
                int which)

返回指定类型的内置静态壁纸的drawable。 根据参数,可绘制的图形可以裁剪和缩放。

Parameters
outWidth int: The width of the returned drawable
outHeight int
scaleToFit boolean: If true, scale the wallpaper down rather than just cropping it
horizontalAlignment float: A float value between 0 and 1 specifying where to crop the image; 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned
verticalAlignment float: A float value between 0 and 1 specifying where to crop the image; 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned
which int: The FLAG_* identifier of a valid wallpaper type. Throws IllegalArgumentException if an invalid wallpaper is requested.
Returns
Drawable A Drawable presenting the built-in default wallpaper image of the given type, or null if no default image of that type is defined on this device.

getBuiltInDrawable

Added in API level 24
Drawable getBuiltInDrawable (int which)

为指定的内置静态系统壁纸获取drawable。

Parameters
which int: The FLAG_* identifier of a valid wallpaper type. Throws IllegalArgumentException if an invalid wallpaper is requested.
Returns
Drawable A Drawable presenting the specified wallpaper image, or null if no built-in default image for that wallpaper type exists.

getBuiltInDrawable

Added in API level 19
Drawable getBuiltInDrawable (int outWidth, 
                int outHeight, 
                boolean scaleToFit, 
                float horizontalAlignment, 
                float verticalAlignment)

返回系统内置静态壁纸的drawable。 根据参数,可绘制的图形可以裁剪和缩放

Parameters
outWidth int: The width of the returned drawable
outHeight int
scaleToFit boolean: If true, scale the wallpaper down rather than just cropping it
horizontalAlignment float: A float value between 0 and 1 specifying where to crop the image; 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned
verticalAlignment float: A float value between 0 and 1 specifying where to crop the image; 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned
Returns
Drawable A Drawable presenting the built-in default system wallpaper image, or null if no such default image is defined on this device.

getBuiltInDrawable

Added in API level 19
Drawable getBuiltInDrawable ()

获取内置静态系统壁纸的drawable。

Returns
Drawable

getCropAndSetWallpaperIntent

Added in API level 19
Intent getCropAndSetWallpaperIntent (Uri imageUri)

获取一个意图,该意图将启动裁剪给定图像并设置设备壁纸的活动。 如果有支持裁剪壁纸的默认HOME活动,则它将被优先选为默认设置。 使用此方法而不是直接创建ACTION_CROP_AND_SET_WALLPAPER意图。

Parameters
imageUri Uri: The image URI that will be set in the intent. The must be a content URI and its provider must resolve its type to "image/*"
Returns
Intent
Throws
IllegalArgumentException if the URI is not a content URI or its MIME type is not "image/*"

getDesiredMinimumHeight

Added in API level 5
int getDesiredMinimumHeight ()

返回壁纸所需的最小高度。 来电者setBitmap(android.graphics.Bitmap)setStream(java.io.InputStream)应事先检查此值,以确保提供的壁纸符合所需的最小高度。 如果返回的值<= 0,则调用者应该使用默认显示的高度。

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

getDesiredMinimumWidth

Added in API level 5
int getDesiredMinimumWidth ()

返回所需的墙纸最小宽度。 来电者setBitmap(android.graphics.Bitmap)setStream(java.io.InputStream)应事先检查此值以确保提供的壁纸符合所需的最小宽度。 如果返回值<= 0,则调用者应该使用默认显示的宽度。

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

getDrawable

Added in API level 5
Drawable getDrawable ()

检索当前的系统壁纸; 如果未设置壁纸,则返回系统内置静态壁纸。 这将作为一个抽象Drawable返回,您可以在View中安装以显示用户当前设置的任何壁纸。

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

getFastDrawable

Added in API level 5
Drawable getFastDrawable ()

getDrawable()一样,但返回的Drawable有一些限制,以尽可能减少其开销。 它永远不会缩放壁纸(如果请求的边界与位图边界匹配,只能将其居中),不允许设置alpha,滤镜或其他属性等。返回的可绘制边界将被初始化为与壁纸相同的边界,因此通常您不需要触摸它。 drawable还假设它将在与屏幕相同密度运行的环境中使用(不是在密度兼容模式下)。

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

getInstance

Added in API level 5
WallpaperManager getInstance (Context context)

检索与给定上下文关联的WallpaperManager。

Parameters
context Context
Returns
WallpaperManager

getWallpaperFile

Added in API level 24
ParcelFileDescriptor getWallpaperFile (int which)

获得一个开放的,可读的文件描述符到给定的壁纸图像文件。 调用者负责在完成摄取文件时关闭文件描述符。

如果没有为特定用户配置特定于锁的墙纸,则此方法在请求 FLAG_LOCK时将返回 null ,而不是返回系统墙纸的图像文件。

Parameters
which int: The wallpaper whose image file is to be retrieved. Must be a single defined kind of wallpaper, either FLAG_SYSTEM or FLAG_LOCK.
Returns
ParcelFileDescriptor

也可以看看:

getWallpaperId

Added in API level 24
int getWallpaperId (int which)

获取给定种类的当前壁纸的ID。 如果没有配置此类壁纸,则返回负数。

每次设置壁纸图像时,都会为其分配新的ID。 这种方法允许调用者确定壁纸图像是否已经改变,无论改变如何发生。

Parameters
which int: The wallpaper whose ID is to be returned. Must be a single defined kind of wallpaper, either FLAG_SYSTEM or FLAG_LOCK.
Returns
int The positive numeric ID of the current wallpaper of the given kind, or a negative value if no such wallpaper is configured.

getWallpaperInfo

Added in API level 7
WallpaperInfo getWallpaperInfo ()

如果当前壁纸是动态壁纸组件,则返回有关该壁纸的信息。 否则,如果它是一个静态图像,只需返回null。

Returns
WallpaperInfo

hasResourceWallpaper

Added in API level 17
boolean hasResourceWallpaper (int resid)

返回是否有任何用户当前设置为使用具有给定资源ID的墙纸。 也就是说,他们的墙纸已经通过setResource(int)设置了相同的资源ID。

Parameters
resid int
Returns
boolean

isSetWallpaperAllowed

Added in API level 24
boolean isSetWallpaperAllowed ()

返回是否允许调用包为主叫用户设置壁纸。 如果此功能返回false ,则任何更改壁纸的尝试都将不起作用。 始终为设备所有者和配置文件所有者返回true

Returns
boolean

也可以看看:

isWallpaperSupported

Added in API level 23
boolean isWallpaperSupported ()

返回主叫用户是否支持壁纸。 如果此功能返回false ,则任何更改壁纸的尝试都将不起作用,并且任何获取壁纸的尝试都将返回null

Returns
boolean

peekDrawable

Added in API level 5
Drawable peekDrawable ()

检索当前的系统壁纸; 如果没有设置壁纸,则返回空指针。 这将作为一个抽象Drawable返回,您可以在View中安装以显示用户当前设置的任何壁纸。

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

peekFastDrawable

Added in API level 5
Drawable peekFastDrawable ()

getFastDrawable()一样,但是如果没有设置壁纸,则返回空指针。

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

sendWallpaperCommand

Added in API level 7
void sendWallpaperCommand (IBinder windowToken, 
                String action, 
                int x, 
                int y, 
                int z, 
                Bundle extras)

发送任意命令到当前活动墙纸。

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

setBitmap

Added in API level 24
int setBitmap (Bitmap fullImage, 
                Rect visibleCropHint, 
                boolean allowBackup, 
                int which)

版本 setBitmap(Bitmap, Rect, boolean) ,允许调用者指定要设置哪些支持的壁纸类别。

Parameters
fullImage Bitmap: A bitmap that will supply the wallpaper imagery.
visibleCropHint Rect: The rectangular subregion of fullImage that should be displayed as wallpaper. Passing null for this parameter means that the full image should be displayed if possible given the image's and device's aspect ratios, etc.
allowBackup boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
which int: Flags indicating which wallpaper(s) to configure with the new imagery.
Returns
int An integer ID assigned to the newly active wallpaper; or zero on failure.
Throws
IOException

也可以看看:

setBitmap

Added in API level 5
void setBitmap (Bitmap bitmap)

将当前系统壁纸更改为位图。 给定的位图被转换为PNG并存储为壁纸。 成功时,广播意向ACTION_WALLPAPER_CHANGED

该方法等效于调用 setBitmap(Bitmap, Rect, boolean)并通过 nullvisibleCrop矩形和 trueallowBackup参数。

此方法要求调用方拥有权限 SET_WALLPAPER

Parameters
bitmap Bitmap: The bitmap to be used as the new system wallpaper.
Throws
IOException If an error occurs when attempting to set the wallpaper to the provided image.

setBitmap

Added in API level 24
int setBitmap (Bitmap fullImage, 
                Rect visibleCropHint, 
                boolean allowBackup)

将当前系统壁纸更改为位图,指定关于完整图像的哪个子矩形可见的提示。 然后操作系统将尽力将整个图像的给定部分呈现为静态系统壁纸图像。 成功时,广播意向ACTION_WALLPAPER_CHANGED

传递 null作为 visibleHint参数等效于通过(0,0, fullImage.getWidth()fullImage.getHeight() )。

此方法要求调用方拥有权限 SET_WALLPAPER

Parameters
fullImage Bitmap: A bitmap that will supply the wallpaper imagery.
visibleCropHint Rect: The rectangular subregion of fullImage that should be displayed as wallpaper. Passing null for this parameter means that the full image should be displayed if possible given the image's and device's aspect ratios, etc.
allowBackup boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
Returns
int An integer ID assigned to the newly active wallpaper; or zero on failure.
Throws
IOException If an error occurs when attempting to set the wallpaper to the provided image.
IllegalArgumentException If the visibleCropHint rectangle is empty or invalid.

setResource

Added in API level 24
int setResource (int resid, 
                int which)

版本 setResource(int) ,允许调用者指定要设置哪些支持的壁纸类别。

Parameters
resid int: The resource ID of the bitmap to be used as the wallpaper image
which int: Flags indicating which wallpaper(s) to configure with the new imagery
Returns
int An integer ID assigned to the newly active wallpaper; or zero on failure.
Throws
IOException

也可以看看:

setResource

Added in API level 5
void setResource (int resid)

将当前系统墙纸更改为给定资源中的位图。 资源作为原始数据流打开并复制到壁纸中; 它必须是有效的PNG或JPEG图像。 成功时,广播意图ACTION_WALLPAPER_CHANGED

此方法要求调用方拥有权限 SET_WALLPAPER

Parameters
resid int: The resource ID of the bitmap to be used as the wallpaper image
Throws
IOException If an error occurs reverting to the built-in wallpaper.

setStream

Added in API level 5
void setStream (InputStream bitmapData)

将当前系统壁纸更改为特定的字节流。 给InputStream复制到持久存储中,现在将用作壁纸。 目前它必须是JPEG或PNG图像。 成功时,广播意图ACTION_WALLPAPER_CHANGED

该方法等效于调用 setStream(InputStream, Rect, boolean)并通过 nullvisibleCrop矩形和 trueallowBackup参数。

此方法要求调用方拥有权限 SET_WALLPAPER

Parameters
bitmapData InputStream: A stream containing the raw data to install as a wallpaper. This data can be in any format handled by BitmapRegionDecoder.
Throws
IOException If an error occurs when attempting to set the wallpaper based on the provided image data.

setStream

Added in API level 24
int setStream (InputStream bitmapData, 
                Rect visibleCropHint, 
                boolean allowBackup, 
                int which)

版本 setStream(InputStream, Rect, boolean) ,允许调用者指定要设置哪些支持的壁纸类别。

Parameters
bitmapData InputStream: A stream containing the raw data to install as a wallpaper. This data can be in any format handled by BitmapRegionDecoder.
visibleCropHint Rect: The rectangular subregion of the streamed image that should be displayed as wallpaper. Passing null for this parameter means that the full image should be displayed if possible given the image's and device's aspect ratios, etc.
allowBackup boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
which int: Flags indicating which wallpaper(s) to configure with the new imagery.
Returns
int An integer ID assigned to the newly active wallpaper; or zero on failure.
Throws
IOException

也可以看看:

setStream

Added in API level 24
int setStream (InputStream bitmapData, 
                Rect visibleCropHint, 
                boolean allowBackup)

将当前系统壁纸更改为特定的字节流,指定关于完整图像的哪个子矩形可见的提示。 然后操作系统将尽力将整个图像的给定部分呈现为静态系统壁纸图像。 来自给定InputStream的数据被复制到永久存储器中,然后将其用作系统壁纸。 目前数据必须是JPEG或PNG图像。 成功时,广播意图ACTION_WALLPAPER_CHANGED

此方法要求调用方拥有权限 SET_WALLPAPER

Parameters
bitmapData InputStream: A stream containing the raw data to install as a wallpaper. This data can be in any format handled by BitmapRegionDecoder.
visibleCropHint Rect: The rectangular subregion of the streamed image that should be displayed as wallpaper. Passing null for this parameter means that the full image should be displayed if possible given the image's and device's aspect ratios, etc.
allowBackup boolean: true if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise.
Returns
int An integer ID assigned to the newly active wallpaper; or zero on failure.
Throws
IOException If an error occurs when attempting to set the wallpaper based on the provided image data.
IllegalArgumentException If the visibleCropHint rectangle is empty or invalid.

也可以看看:

setWallpaperOffsetSteps

Added in API level 7
void setWallpaperOffsetSteps (float xStep, 
                float yStep)

对于使用多个虚拟屏幕显示壁纸的应用程序,指定虚拟屏幕之间的步长。 例如,如果启动器有3个虚拟屏幕,则它将指定0.5的xStep,因为这些屏幕的X偏移量分别为0.0,0.5和1.0

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

setWallpaperOffsets

Added in API level 5
void setWallpaperOffsets (IBinder windowToken, 
                float xOffset, 
                float yOffset)

设置当前壁纸在任何较大空间内的显示位置,当该壁纸在给定窗口后面可见时。 X和Y偏移量是从0到1的浮点数,表示壁纸应放置在屏幕空间内的位置。 这些只有在壁纸大于显示器时才有意义。

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

suggestDesiredDimensions

Added in API level 5
void suggestDesiredDimensions (int minimumWidth, 
                int minimumHeight)

仅供当前家庭应用程序使用,以指定要使用的壁纸大小。 这允许这些应用程序具有比物理屏幕更大的虚拟壁纸,以匹配其工作区的大小。

请注意开发者,他们似乎没有阅读过这篇文章。 这是家庭应用程序要告诉他们想要什么大小的壁纸。 没有人应该这样称呼它! 当然不是其他非家庭应用程序更改壁纸。 这些应用程序应该检索建议的大小,以便可以构建与之匹配的壁纸。

此方法要求调用方拥有权限 SET_WALLPAPER_HINTS

Parameters
minimumWidth int: Desired minimum width
minimumHeight int: Desired minimum height

Hooray!