1

我有一个应用程序将壁纸应用于主屏幕,其图像与屏幕尺寸相匹配。这是我设置壁纸的代码:

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

它在大多数设备上都能完美运行,但对 Galaxy suggestDesiredDimensions()s4 和 Galaxy s3 完全没有影响(我想其他三星手机也会有同样的问题)。在此手机上,无论所需尺寸如何,图像都会被缩放。

但我发现Backgrounds HD应用程序没有这个问题。所以我想知道如果我的壁纸的实际尺寸为 1080x1920,如何在不裁剪的情况下在 Galaxy s4(或 s3)上设置壁纸?

4

1 回答 1

1

好吧,我使用Set as意图修复了它。似乎无法在 TouchWiz 上设置尺寸。这是我的代码:

        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);
于 2013-08-27T09:47:53.187 回答