首页 > 解决方案 > 使用 DownloadManager 下载视频文件时,应用程序在 Android 10 上崩溃

问题描述

应用程序在设置时崩溃setDestinationInExternalPublicDir()

 val videoDir = Environment.getDataDirectory().absolutePath + "/applicationfiles/.tutorial"
downloadRequest.setDestinationInExternalPublicDir(videoDir, videoName)

E/AndroidRuntime:致命异常:主进程:app.package,PID:19275 java.lang.IllegalStateException:不是标准目录之一:/data/applicationfiles/.tutorial at android.os.Parcel.createException(Parcel.java:2079 ) 在 android.os.Parcel.readException(Parcel.java:2039) 在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188) 在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) 在 android.content .ContentProviderProxy.call(ContentProviderNative.java:658) 在 android.content.ContentProviderClient.call(ContentProviderClient.java:558) 在 android.content.ContentProviderClient.call(ContentProviderClient.java:546) 在 android.app.DownloadManager$Request。 setDestinationInExternalPublicDir(DownloadManager.java:569) 在 app.package.startDownloadingFile(ExerciseTutorialPresenter.kt:159) 在 app.package.downloadVideoFiles(ExerciseTutorialPresenter.kt:142)

标签: androidandroid-download-managerdownload-manager

解决方案


setDestinationInExternalPublicDir(dirType: String!, subPath: String!)

对于面向 Android 10 及更高版本的应用程序,dirType此方法的第一个参数必须是已知的公共目录之一,例如Environment.DIRECTORY_DOWNLOADSEnvironment.DIRECTORY_PICTURESEnvironment.DIRECTORY_MOVIES等。


推荐阅读