W/DownloadManager: 中止下载请求 17: 未能创建目标文件 /storage/emulated/0/Ringtone/Fav_Ringtone.mp3

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

我正在尝试下载我的 mp3 文件并想将其保存到特定位置的内部存储器中。

但是我每次下载都失败。

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();
        }
    }

我认为是模拟器故障。因为大多数时候我的模拟器无法下载文件(SmartGaga)

将您的代码更改为此

    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();}
    }