Android - How to set the wallpaper image? [duplicate]

寵の児 提交于 2019-11-27 19:33:20
Maidul

Hi you can use this code if You have Image path.

is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
    bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
    System.out.println("Hi I am try to open Bit map");
    wallpaperManager = WallpaperManager.getInstance(this);
    wallpaperDrawable = wallpaperManager.getDrawable();
    wallpaperManager.setBitmap(useThisBitmap);

if you have image URI then use this

wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);

Let me know if there is any issue .

Samuh

If you have the image URL you can open the resource it represent using the stream(abstraction): new URL("your.image.url.com").openStream(). This method call will return an object of type InputStream which you can pass as an argument to setStream() method.

If you dont want to specify a stream directly, you can open the remote stream, create a Bitmap and then either use a WallpaperManager instance or do a context.setWallpaper(bitmap)(this is deprecated) to set your bitmap as the wallpaper.

For reference take a look at this thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!