Wallpaper not properly fit on Samsung devices

不羁的心 提交于 2019-12-13 07:57:12

问题


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();
    }

}

Micromax canvas screenshot :-

Samsung S3 screenshot :


回答1:


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";   
}


来源:https://stackoverflow.com/questions/32201161/wallpaper-not-properly-fit-on-samsung-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!