SecurityException:不支持的路径/storage/emulated/999/Download/somefile.pdf

时间:2019-04-29 08:46:55

标签: android securityexception runtime-permissions

我正在尝试将一些.pdf文件从服务器下载到download文件夹

此异常是在某些设备上随机抛出的

运行android(8,7,6)的小米:仅在此设备上崩溃的97%

已授予存储运行时权限,并且可以运行

我发现即使经过运行时许可,某些设备仍无法工作

file_path.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path
        name="images"
        path="images/" />
    <external-files-path
        name="share"
        path="share/" />
    <external-files-path
        name="reminder_images"
        path="reminder_images/" />
</paths>

AndroidManifest

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

StackTrace

Caused by java.lang.SecurityException: Unsupported path /storage/emulated/999/Download/Somefile.pdf
       at android.os.Parcel.readException(Parcel.java:2013)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
       at android.content.ContentProviderProxy.insert(ContentProviderProxy.java:476)
       at android.content.ContentResolver.insert(ContentResolver.java:1555)
       at android.app.DownloadManager.enqueue(DownloadManager.java:1163)
       at com.esafirm.rxdownloader.RxDownloader.download(RxDownloader.java:83)
       at com.esafirm.rxdownloader.RxDownloader.download(RxDownloader.java:60)
       at in.okcredit.app.ui.account.AccountActivity.onReportGenerated(AccountActivity.java:320)
       at in.okcredit.app.ui.account.AccountPresenter$1.onSuccess(AccountPresenter.java:118)
       at in.okcredit.app.ui.account.AccountPresenter$1.onSuccess(AccountPresenter.java:111)
       at io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.run(SingleObserveOn.java:81)
       at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:119)
       at android.os.Handler.handleCallback(Handler.java:794)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:176)
       at android.app.ActivityThread.main(ActivityThread.java:6651)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)

0 个答案:

没有答案