2016-01-22 45 views
4

首先,在這個問題上有很多問題,但沒有一個反映我的問題。例如,我讀了thisthisDownloadManager IllegalStateException在DIRECTORY_DOWNLOADS中創建下載文件

,我有這個問題,是在非常少數情況下,我的功能setDestinationInExternalPublicDir結果在下面的堆棧跟蹤:

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保存文件的位置。

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%的用戶可能會遇到此錯誤。什麼可能導致它?

回答

20

在編寫我的問題的過程中,我注意到我可能自己解決了這個問題。我將寫出有問題的設備型號,但在Crashlytics上它顯示「未知」。我點擊了,並且顯示了以下模型:GI I9500 TMMARS。運行Android 4.

TMMARS似乎是來自Trend Micro的軟件。

趨勢科技移動應用程序信譽服務或TMMARS是一個基於雲的服務 自動識別基於應用 行爲移動威脅。

系統極有可能不像應用程序所期望的那樣運行,僅僅因爲它是一個威脅檢測環境。

實例崩潰報告:

example crash report from Crashlytics

+0

非常感謝您! – heloisasim

相關問題