I want to set wallpaper through app for all device but problem is that my following approach work for Moto, sony, micromax but not properly fit for any samsung device like samsung S3, samsung duos, Tab etc, in these devices wallpaper is much zoom see in screenshots.
please guide me for solve this problem.
private void setMyWallpaper() {
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
Drawable drawable = null;
if (who.equals("color"))
drawable = getResources().getDrawable(colorWallpaper[i]);
else
drawable = getResources().getDrawable(grayWallpaper[i]);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Bitmap wallpaper = Bitmap.createScaledBitmap(bitmap, width, height,true);
myWallpaperManager.suggestDesiredDimensions(width, height);
try {
myWallpaperManager.setBitmap(wallpaper);
Log.i("Wall", "Wallpaper set successfully ");
} catch (IOException e) {
e.printStackTrace();
}
}
I solve this problem using call INTENT in place of WallpaperManager
like this:
//load file
File file = new File(getGalleryPath());
if ( file.exists()) {
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.fromFile(file), "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
} else {
Log.d("TEST", "file not exixts.");
}
// method for getting Image path
private static String getGalleryPath() {
return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/MyImages/IMG-20160326-WA0083.jpg";
}