Search code examples
androiddownloadpicassowallpaper

How do i download images onto device to be able to set them as a Wallpaper


Is there a way I can download images on android and locate them on the device after the image is downloaded set as a new wallpaper with a click from a button.

Help would be greatly appreciated!


Solution

  • ImageRequest imgRequest = new ImageRequest(url, new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap _bitmapScaled) {
    
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            _bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
    
            //you can create a new file name "test.jpg" in sdcard folder.
            File f = new File(Environment.getExternalStorageDirectory()
                                    + File.separator + "test.jpg")
            f.createNewFile();
            //write the bytes in file
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
    
            // remember close de FileOutput
            fo.close();
    
    
        }
        }, 0, 0, ImageView.ScaleType.CENTER_CROP, Bitmap.Config.ARGB_8888, 
        new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
           //do stuff
        }
    });