问题描述
可能重复:
机器人 - 如何设置墙纸图像
我甲肝开始在做Android应用程序。我想设置wallpaer在Android的这后台运行(使用服务)和壁纸将在5分钟在后台更改。我把图像文件中绘制对象。任何人都请发送的编码设置wallpaer 5分钟后retriving吧..
I hav started doing app in Android. I want to set wallpaer in Android which run in Background(using Service) and the wallpaper will change within 5 minute in background. I keep the image files in Drawable. Anyone kindly send the coding for setting the wallpaer and retriving it after 5 minutes..
感谢名单提前。
推荐答案
Here就是一个例子。但不幸的是它为我不起作用。基本上我用下面的code:
Here is an example. But unfortunately it does not work for me. Basically I am using the following code:
code:
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.");
}
在 imageFilePath
是正确的,据我可以告诉(我还针对不同的东西,在工作)。没有错误或异常。我的手机的背景是在调用这个程序后,只是空的。我究竟做错了什么?
The imageFilePath
is correct as far as I can tell (as I also for different stuff that is working). There is no error or exception. The background of my phone is just empty after calling this app. What am I doing wrong?
这篇关于如何在Android中设置壁纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!