使用 DownloadManager 下载视频文件时,应用程序在 Android 10 崩溃
Application is crashing on Android 10 while downloading video files using DownloadManager
应用在设置时崩溃 setDestinationInExternalPublicDir()
val videoDir = Environment.getDataDirectory().absolutePath + "/applicationfiles/.tutorial"
downloadRequest.setDestinationInExternalPublicDir(videoDir, videoName)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.package, PID: 19275
java.lang.IllegalStateException: Not one of standard directories: /data/applicationfiles/.tutorial
at android.os.Parcel.createException(Parcel.java:2079)
at android.os.Parcel.readException(Parcel.java:2039)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:658)
at android.content.ContentProviderClient.call(ContentProviderClient.java:558)
at android.content.ContentProviderClient.call(ContentProviderClient.java:546)
at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:569)
at app.package.startDownloadingFile(ExerciseTutorialPresenter.kt:159)
at app.package.downloadVideoFiles(ExerciseTutorialPresenter.kt:142)
setDestinationInExternalPublicDir(dirType: String!, subPath: String!)
对于以 Android 10 及更高版本为目标的应用程序,此方法的第一个参数 dirType
必须是已知的 public 目录之一,例如 Environment.DIRECTORY_DOWNLOADS
、Environment.DIRECTORY_PICTURES
、Environment.DIRECTORY_MOVIES
、等等
应用在设置时崩溃 setDestinationInExternalPublicDir()
val videoDir = Environment.getDataDirectory().absolutePath + "/applicationfiles/.tutorial"
downloadRequest.setDestinationInExternalPublicDir(videoDir, videoName)
E/AndroidRuntime: FATAL EXCEPTION: main Process: app.package, PID: 19275 java.lang.IllegalStateException: Not one of standard directories: /data/applicationfiles/.tutorial at android.os.Parcel.createException(Parcel.java:2079) at android.os.Parcel.readException(Parcel.java:2039) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) at android.content.ContentProviderProxy.call(ContentProviderNative.java:658) at android.content.ContentProviderClient.call(ContentProviderClient.java:558) at android.content.ContentProviderClient.call(ContentProviderClient.java:546) at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:569) at app.package.startDownloadingFile(ExerciseTutorialPresenter.kt:159) at app.package.downloadVideoFiles(ExerciseTutorialPresenter.kt:142)
setDestinationInExternalPublicDir(dirType: String!, subPath: String!)
对于以 Android 10 及更高版本为目标的应用程序,此方法的第一个参数 dirType
必须是已知的 public 目录之一,例如 Environment.DIRECTORY_DOWNLOADS
、Environment.DIRECTORY_PICTURES
、Environment.DIRECTORY_MOVIES
、等等