【问题标题】:WallpaperManager suggestDesiredDimensions() has no effect on samsung phonesWallpaperManager 建议DesiredDimensions() 对三星手机没有影响
【发布时间】:2013-08-21 16:05:51
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: android wallpaper homescreen


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多