Question

how to set image wallpaper full image background screen. My code

Bitmap bmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.splash);

            DisplayMetrics outMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
            int w = outMetrics.widthPixels;
            int h = outMetrics.heightPixels;
            Bitmap wallpaper=Bitmap.createScaledBitmap(bmap, w, h, true);

                            WallpaperManager m = WallpaperManager.getInstance(getApplicationContext());
            try {
                m.setBitmap(wallpaper);
            } catch (IOException e) {
                e.printStackTrace();
            }

image

image

I need image full set a wall paper

No correct solution

OTHER TIPS

public void changeWallpaper(String path) {
   FileInputStream is;
         BufferedInputStream bis;
                WallpaperManager wallpaperManager;
                Drawable wallpaperDrawable;
                File sdcard = Environment.getExternalStorageDirectory();
                try {
                        is = new FileInputStream(new File(path));
                        bis = new BufferedInputStream(is);
                        Bitmap bitmap = BitmapFactory.decodeStream(bis);
                        Bitmap useThisBitmap = Bitmap.createBitmap(bitmap);
                        wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
                        wallpaperDrawable = wallpaperManager.getDrawable();
                        wallpaperManager.setBitmap(useThisBitmap);
                } catch (Exception e) {
                        e.printStackTrace();
                }
    }

Above code works for me And do not forgot to add

<uses-permission android:name="android.permission.SET_WALLPAPER" />

in AndroidManifest.xml file

You can convert your drawables into bitmap also

BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_name);

You can launch Crop intent by start activity for result and retrieve it in result and then use wallpaper manager class. like this :

Uri imgUri=Uri.parse("android.resource://your.package.name/"+R.drawable.image); 
Intent intent = new Intent("com.android.camera.action.CROP");  
intent.setDataAndType(imgUri, "image/*");  
intent.putExtra("crop", "true");  
intent.putExtra("aspectX", 1);  
intent.putExtra("aspectY", 1);  
intent.putExtra("outputX", 80);  
intent.putExtra("outputY", 80);  
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CODE_CROP_PHOTO);

and use Wallpaper manager in your onResult function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top