可能重复: Android -如何设置壁纸图像
我已经开始用Android做应用了。我想设置在Android壁纸运行在后台(使用服务),壁纸将在5分钟内改变背景。我把图像文件放在可绘制的地方。任何人都可以发送设置壁纸的代码,并在5分钟后检索它。
提前鸣谢。
发布于 2011-02-03 21:32:36
下面是一个例子。但不幸的是,这对我不起作用。基本上,我使用的代码如下:
代码:
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
是正确的(因为我也对不同的东西起作用)。没有错误或异常。打电话给这个应用程序后,我手机的背景是空的。我做错了什么?
发布于 2011-05-18 09:02:10
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
.................................................如果您有图像URI,那么使用下面的
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
.如果有什么问题,请告诉我。
发布于 2010-08-05 16:36:24
您可能想看看WallpaperManager。
编写一个简单的服务,您可以使用计时定期更改墙纸。
https://stackoverflow.com/questions/3416895
复制相似问题