1
I am developing an application that after 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 library Picasso to manipulate my images but I don’t know how to download the file and then save the image in my directory /data/data/pt.MEU_PROJECTO/
so I can popular mine ImageView
'even if the user has no internet connection.
I have the following function created to save my images that I built from a tutorial but I don’t 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 get the image, once it’s stored, to the correct directory to popular my ImageView
. I found this code but there were many users who will comment not working.
Uri uri = Uri.parse("file:///data/data/pt.MEU_PROJECTO/file.jpg");
image.setImageURI(uri);
This might help http://answall.com/questions/44092/como-salvar-recuperar-imagem-na-mem%C3%B3ria-no-android
– Skywalker