I'm trying to create a voice messaging android app using firebase storage as backend, but i'm having issue while downloading mp3 file while it uploads successfully.
Can somebody please provide simple code just to download an audio file from storage. I'm new at android development , so sorry for being noob
i've added all the permissions in my manifest file like bellow
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Tis is my uploading code
private void uploadAudio() {
pd=new ProgressDialog(this);
pd.setMessage("Uploading");
pd.show();
StorageReference filepath = mstorage.child("Audio").child("New_Audio");
Uri uri = Uri.fromFile(new File(mFileName));
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
pd.dismiss();
}
});
}
And for downloading
private void startdownload() {
down = mstorage.child("Audio/");
File localFile = null;
try {
localFile = File.createTempFile("Audio", "mp3");
} catch (IOException e) {
e.printStackTrace();
}
down.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(),"Downloded",Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
}
});
}