2013-08-21 27 views
0

我有一個應用程序,將壁紙應用到主屏幕與圖像匹配的屏幕尺寸。 這是我設置牆紙代碼:WallpaperManager suggestDesiredDimensions()對三星手機沒有任何影響

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

而且它在大多數設備完美workd,但suggestDesiredDimensions()對星系S4和Galaxy S3(我想其他的三星手機將有同樣的問題)完全沒有影響。無論所需尺寸如何,此手機圖像都會縮放。我發現Backgrounds HD應用程序不存在這個問題。所以我想知道如何在沒有裁剪的情況下在銀河s4(或s3)上設置壁紙,假設我的壁紙的實際尺寸爲1080x1920?

回答

0

那麼,我使用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); 
相關問題