I am developing an application in which I want to be able to download a JSON file from a server and then be consumed on the device locally (in order to feed certain activities with information).
This I do to be able to update the information remotely and thus be updated without the need to launch a new update with the new information in the Play Store.
I am currently using Firebase. Then I uploaded an file to Cloud Storage of it and I'm trying to download it. The code you use is the following:
private void downloadfile() {
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference httpsReference = storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/......");
File localFile = null;
try {
localFile = File.createTempFile("dishes", "json");
} catch (IOException e)
{
e.printStackTrace();
}
httpsReference.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot)
{
Toast.makeText(MainActivity.this, "Se descargo bien", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(MainActivity.this, "Error al descragar", Toast.LENGTH_SHORT).show();
}
});
}
The code will take it out of the official documentation of Firebase. link
According to this, the file is downloaded, but I can not find it anywhere. What is the error? Or how can I locate my file?
PD: I use the .getAbsolutePath () to show me where I "save", but the route it shows does not exist.
File localFile = null;
Utilio el metodo localFile.getAbsolutePath();