DownloadManager IllegalStateException在DIRECTORY_DOWNLOADS中创建下载 [英] DownloadManager IllegalStateException creating a download in DIRECTORY_DOWNLOADS

查看:141
本文介绍了DownloadManager IllegalStateException在DIRECTORY_DOWNLOADS中创建下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,关于此主题的问题很多,但没有一个问题反映了我的问题.例如,我已阅读

Firstly, there are a lot of questions on this subject, but none reflect my issue. I have for example read this and this.

我遇到的问题是,在极少数情况下,我对setDestinationInExternalPublicDir的函数导致以下堆栈跟踪:

The issue that I have, is that in an extremely small number of cases, my function to setDestinationInExternalPublicDir results in the following stack trace:

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.onlinetvrecorder.otrapp2.listeners.DownloadUpdateReceiver: java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2274)
       at android.app.ActivityThread.access$1500(ActivityThread.java:131)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4791)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
       at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:496)
       at com.myapp.Utils.download(SourceFile:752)
       at com.myapp.Receiver.onReceive(SourceFile:20)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2267)
       at android.app.ActivityThread.access$1500(ActivityThread.java:131)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4791)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at dalvik.system.NativeStart.main(NativeStart.java)

我正在使用标准的Environment常量来告诉DownloadManager将文件保存在何处.

I am using a standard Environment constant to tell the DownloadManager where to save the file.

android.app.DownloadManager dm = (android.app.DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

DownloadManager.Request request = new DownloadManager.Request(Uri.parse("url.to.file.ext"));
request.setMimeType("mime/type");

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    Utils.setDownloadRequestVisibility(request, android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "file.ext");
request.setTitle(context.getString(R.string.download));

dm.enqueue(request);

如前所述,可能甚至没有1%的用户遇到此错误.可能是什么原因造成的?

As previously stated, there are perhaps not even 1% of users getting this error. What could be causing it?

推荐答案

在编写我的问题的过程中,我注意到我自己可能已经解决了这个问题.我要写的是有问题的设备模型,但是在Crashlytics上它显示为未知".我单击了该按钮,然后显示以下模型:GI I9500 TMMARS.运行Android 4.

In the course of writing my question, I noticed that I had probably just solved the issue myself. I was going to write what the offending device model was, but on Crashlytics it displayed "Unknown". I clicked upon that, and the following model was revealed: GI I9500 TMMARS. Running Android 4.

TMMARS似乎是 Trend Micro 的软件.

TMMARS appears to be software from Trend Micro.

趋势微移动应用信誉服务或TMMARS是基于云的 可根据应用自动识别移动威胁的服务 行为.

Trend Micro Mobile App Reputation Service or TMMARS is a cloud-based service that automatically identifies mobile threats based on app behaviors.

该系统极有可能没有按App预期的那样运行,仅因为它是一个威胁检测环境.

It is extremely likely that the system is not behaving as the App expects it to, simply because it is a threat detection environment.

崩溃报告示例:

这篇关于DownloadManager IllegalStateException在DIRECTORY_DOWNLOADS中创建下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆