W/DownloadManager: Aborting request for download 17: Failed to create target file /storage/emulated/0/Ringtone/Fav_Ringtone.mp3
O

1

0

I am trying to download my mp3 file and want to save it to internal storage at a specific location.

But every time my download is failing.

Logcat error message

01-01 08:36:09.295 154-748/android.process.media W/DownloadManager: Aborting request for download 
17: Failed to create target file /storage/emulated/0/Ringtone/Fav_Ringtone.mp3

Download Method

   public void Save_mp3_internal_Storage(Uri uri,Context context){

        String destination = Environment.getExternalStorageDirectory()+"/Ringtone/";

        Delete_mp3_internal_Storage(new File(destination,"Fav_Ringtone.mp3"));

        DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        DownloadManager.Request request = new DownloadManager.Request(uri)
                .setDestinationUri(Uri.fromFile(new File(destination,"Fav_Ringtone.mp3")))
                .setTitle("Ringtone Downloading")
                .setNotificationVisibility(1);
                 manager.enqueue(request);
    }

    public void Delete_mp3_internal_Storage(File file){
        if (file.exists()){
            file.delete();
        }
    }

I think it is an emulator fault. because most of the time my emulator fails to download the files(SmartGaga)

Oglethorpe answered 11/6, 2021 at 7:24 Comment(8)
Ringtones......Susette
What android version are you trying? Did you give storage read/write permission?Eliott
@SyedAfeef I added read and write permission to my manifest. Api leval 30Oglethorpe
It's best practice to download files into Environment.DIRECTORY_DOWNLOADS for the latest android And did you give permission to the app? just writing it in manifest won't grant the permission. goto app permission and set it to allowed.Eliott
@Syed Afeef The DownloadManager does not need those permissions.Susette
Ringtones !!!!!!!!!!!!!Susette
@Susette What do you want to say through Ringtone!!!!!!!!!!!!!Oglethorpe
I did not say ringtone or Ringtone. I said: Ringtones.Susette
O
0

change your code to this

    public void Save_mp3_internal_Storage(Uri uri, Context context){

        Delete_mp3_internal_Storage(context);

        DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        DownloadManager.Request request = new DownloadManager.Request(uri);
                request.setDestinationInExternalFilesDir(context,Environment.DIRECTORY_ALARMS,"Fav_Ringtone.mp3")
                .setTitle("Ringtone Downloading")
                .setNotificationVisibility(1);
                 manager.enqueue(request);
    }

    public void Delete_mp3_internal_Storage(Context context){
       File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_ALARMS),"Fav_Ringtone.mp3");
       if (file.exists()){file.delete();}
    }
Oglethorpe answered 11/6, 2021 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.