-1

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!

Adrien Zier
  • 687
  • 1
  • 7
  • 28

1 Answers1

0
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
    }
});
Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77