You need parse the Json in a model.
Then you can get the url property and download it to the file system. You can use HttpUrlConnection to do this or if you want use the Picasso library with Target Picasso and download it in the file system.
Let me show you an example.
Using Picasso:
public static void downloadImageWithPicasso(Context context, String url) {
Picasso.with(context)
.load(your_url_from_model)
.into(saveUsingTarget(url));
}
private static Target saveUsingTarget(final String url){
Target target = new Target(){
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + url);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
Log.e("IOException", e.getLocalizedMessage());
}
}
}).start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
return target;
}
Using HttpUrlConnection
public void downloadImageWithUrlConnection(){
try{
URL url = new URL("your_url_from_model");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File sdCardPath = Environment.getExternalStorageDirectory().getAbsoluteFile();
String filename = "file_name.png";
File file = new File(sdCardPath,filename);
file.createNewFile();
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ){
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
IMPORTANT: If you want use the HttpURLConnection options, you need run this in a background thread.
I hope this helps you.