可能重复:
Android - 如何设置壁纸图像
我开始在Android上做应用程序.我想在Android中设置wallpaer,它在后台运行(使用服务),壁纸将在5分钟后在后台更改.我将图像文件保存在Drawable中.任何人都会发送编码来设置wallpaer并在5分钟后重新开始.
Thanx提前.
这是一个例子.但不幸的是,它对我不起作用.基本上我使用以下代码:
码:
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(this);
String imageFilePath = getFilePath(imageUri);
Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath);
if (myBitmap != null) {
try {
myWallpaperManager.setBitmap(myBitmap);
} catch (IOException e) {
showToast(ImageDisplay.this,
"Failed to set Backgroundimage");
}
} else {
showToast(ImageDisplay.this, "Failed to decode image.");
}
Run Code Online (Sandbox Code Playgroud)
imageFilePath据我所知,这是正确的(因为我也在使用不同的东西).没有错误或异常.在调用此应用程序后,我的手机背景是空的.我究竟做错了什么?