【发布时间】:2011-09-02 15:15:41
【问题描述】:
我已经开始在 Android 中开发应用程序。我想在 Android 中设置在后台运行的壁纸(使用服务),壁纸将在 5 分钟内在后台更改。我将图像文件保存在 Drawable 中。任何人都请发送设置wallpaer的代码并在5分钟后恢复它..
提前感谢。
【问题讨论】:
标签: android
我已经开始在 Android 中开发应用程序。我想在 Android 中设置在后台运行的壁纸(使用服务),壁纸将在 5 分钟内在后台更改。我将图像文件保存在 Drawable 中。任何人都请发送设置wallpaer的代码并在5分钟后恢复它..
提前感谢。
【问题讨论】:
标签: android
Here is an example。但不幸的是,它对我不起作用。基本上我使用的是以下代码:
代码:
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 是正确的(因为我也适用于不同的工作)。没有错误或异常。调用此应用后,我的手机背景为空。我做错了什么?
【讨论】:
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);
.......如果有任何问题,请告诉我。
【讨论】:
您可能想查看WallpaperManager。
编写一个简单的服务,您可以使用Timer 定期更换壁纸。
【讨论】: