Question

I have an app that applies wallpaper to the home screen with images that match the screen size. This is my code for setting wallpapers:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
   BitmapFactory.decodeResource(getResources(), wallpapersPagerAdapter.getWallpaperId(position), options);
   wallpaperManager.suggestDesiredDimensions(options.outWidth, options.outHeight);

   wallpaperManager.setResource(wallpapersPagerAdapter.getWallpaperId(position));
} catch (IOException e) {
    Log.e(Constants.LOG_TAG, e.getMessage());
    Toast.makeText(MainActivity.this, R.string.err_can_not_set_wallpaper, Toast.LENGTH_SHORT).show();
    return;
}

And it workd perfectly on the most devices, but suggestDesiredDimensions() has absolutely no effect on galaxy s4 and galaxy s3(I suppose other samsung phones will have the same problem). On this phones image being scaled regardless of desired dimensions.

But I've found that Backgrounds HD application doesn't have this problem. So I wonder how is it possible to set wallpapers on galaxy s4(or s3) without croping it, assuming that my wallpapers have real size 1080x1920?

Was it helpful?

Solution

Well, I fixed it using Set as intent. It seems that it's no way to set dimensions on TouchWiz. Here is my code:

        Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
        MimeTypeMap map = MimeTypeMap.getSingleton();

        String mimeType = map.getMimeTypeFromExtension("jpg");
        File file = new File(filePath);

        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, mimeType);
        intent.putExtra("mimeType", mimeType);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        context.hideProgressDialog();
        context.startActivityForResult(Intent.createChooser(intent, "Set as"),
                Constants.REQUEST_CODE_SET_WALLPAPER);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top