0

众所周知,android 带有 3 个或 5 个或 7 个主屏幕。我想以编程方式在单个主屏幕上设置壁纸图像,并为所有其他主屏幕修复它。

我使用了以下代码:

 Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
 Bitmap bmp = Bitmap.createScaledBitmap(wallpaperImage,display.getWidth(),display.getHeight(), true);
 setWallpaper(bmp);

并且设置了壁纸图像,但它跨越了所有 3 个主屏幕。如何将其修复到一个屏幕上,以便在用户切换主屏幕时显示单个图像。

4

2 回答 2

0

通过使用以下代码,您可以设置

    Uri sendUri = Uri.fromFile(externalFile)
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setDataAndType(sendUri, "image/jpg");
    intent.putExtra("mimeType", "image/jpg");
    startActivityForResult(Intent.createChooser(intent, "Set As"), 200);

并在 androidmanifest.xml 中添加权限

于 2014-03-19T03:30:00.233 回答
0
File f = new File(Environment.getExternalStorageDirectory(), "1.jpg");
String path = f.getAbsolutePath();
File f1 = new File(path);

if(f1.exists()) {
    Bitmap bmp = BitmapFactory.decodeFile(path);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
    WallpaperManager m=WallpaperManager.getInstance(this);

    try {
        m.setBitmap(bmp);
    } catch (IOException e) {
        e.printStackTrace();
    }
} 

打开 Androidmanifest.xml 文件,添加使用权限作为

'uses-permission android:name="android.permission.SET_WALLPAPER" /'

试试这个,让我知道会发生什么..

于 2012-11-01T11:27:27.770 回答