I'm developing an application that once installed, the first time it is initialized it goes to the server to fetch all the images necessary for the user to use the application.
I chose the Picasso library to manipulate my images but I do not know how I can download the file and then save the image in the my directory /data/data/pt.MEU_PROJECTO/
so that I can even% my ImageView
's even if you do not have an internet connection.
I have the following function created to save my images that I built from a tutorial but I do not know which parameter of the Picasso class I should pass or which directory is being used to save the images.
public static void saveAssetImage(Context context, String assetName){
File fileDirectory = context.getFilesDir();
File fileToWrite = new File(fileDirectory, assetName);
AssetManager assetManager = context.getAssets();
try{
InputStream in = assetManager.open(assetName);
FileOutputStream out = new FileOutputStream(fileToWrite);
in.close();
out.close();
}catch (IOException e){
e.printStackTrace();
}
}
saveAssetImage(getApplicationContext(), Picasso.with(this).load(urlImagem).fetch());
I also need to know how I can fetch the image, once it has been saved, to the correct directory to popular my ImageView
. I found this code but there were a lot of users who commented that it was not working.
Uri uri = Uri.parse("file:///data/data/pt.MEU_PROJECTO/file.jpg");
image.setImageURI(uri);