0

As we know android comes with 3 or 5 or 7 home screens. I want to set wallpaper image on a single home screen programatically and fix it for all other home screens.

I used the following code:

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

And wallpaper image is set but it spans across all 3 home screen. How can I fix it to one screen so that if user swaps home screen a single image will display.

SilentGhost
  • 307,395
  • 66
  • 306
  • 293

2 Answers2

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

Open Androidmanifest.xml file and the add uses Permission as

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

Try this and let me know what happen..

ckpatel
  • 1,926
  • 4
  • 18
  • 34
0

By using below code you can set

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

and also add permission in androidmanifest.xml

Zeeshan Mirza
  • 4,549
  • 3
  • 22
  • 32