我正在开发一个应用程序,可以显示来自服务器的不同照片,用户可以将所选照片设置为其设备的壁纸。我使用了给定的代码来设置壁纸,它可以正常工作,但图像未正确设置,它无法适应屏幕。我使用了以下代码。
String dirPath = getFilesDir().toString();
String folder = mPhotos.get(nextPosition - 1).getCategory();
String filePath = dirPath + "/PhotoViewer/" + folder + "/"
+ mPhotos.get(nextPosition - 1).getFileName();
File imageFile = new File(filePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile
.getAbsolutePath());
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try
{
myWallpaperManager.setBitmap(bitmap);
Toast.makeText(PhotoActivity.this, "Wallpaper set",
Toast.LENGTH_SHORT).show();
} catch(IOException e){
Toast.makeText(PhotoActivity.this, "Error setting wallpaper",
Toast.LENGTH_SHORT).show();
}