【问题标题】:Application is crashing on Android 10 while downloading video files using DownloadManager使用 DownloadManager 下载视频文件时,应用程序在 Android 10 上崩溃
【发布时间】:2019-11-21 04:17:04
【问题描述】:

设置setDestinationInExternalPublicDir()时应用崩溃

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

E/AndroidRuntime: 致命异常: main 进程:app.package,PID:19275 java.lang.IllegalStateException:不是标准目录之一:/data/applicationfiles/.tutorial 在 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)

【问题讨论】:

    标签: android android-download-manager download-manager


    【解决方案1】:

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

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

    【讨论】:

    • 好的,那如果我不想暴露下载的文件并且我正在使用 Environment.getDataDirectory() 下载路径呢?
    • 对于我提出的问题,Android 10 仅接受已知的公共目录是正确的。对于“data/data”等其他文件夹,我们可以使用 downloadRequest.setDestinationInExternalFilesDir(context, filePath, fileName)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多