墙纸不适合三星设备
Wallpaper not properly fit on Samsung devices
我想通过应用程序为所有设备设置墙纸,但问题是我的以下方法适用于 Moto、sony、micromax 但不适用于 any三星 设备,如 samsung S3、samsung duos、Tab 等,在这些设备中,墙纸放大很多,请参见屏幕截图。
请指导我解决这个问题。
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();
}
}
Micromax canvas 屏幕截图:-
三星S3截图:
我使用调用 INTENT 代替 WallpaperManager
解决了这个问题,如下所示:
//加载文件
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.");
}
//获取图片路径的方法
private static String getGalleryPath() {
return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/MyImages/IMG-20160326-WA0083.jpg";
}
我想通过应用程序为所有设备设置墙纸,但问题是我的以下方法适用于 Moto、sony、micromax 但不适用于 any三星 设备,如 samsung S3、samsung duos、Tab 等,在这些设备中,墙纸放大很多,请参见屏幕截图。
请指导我解决这个问题。
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();
}
}
Micromax canvas 屏幕截图:-
三星S3截图:
我使用调用 INTENT 代替 WallpaperManager
解决了这个问题,如下所示:
//加载文件
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.");
}
//获取图片路径的方法
private static String getGalleryPath() {
return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/MyImages/IMG-20160326-WA0083.jpg";
}