2016-12-19 11 views
4

我在我的android項目中使用了DownloadManager來下載文件。爲什麼IllegalArgumentException在使用DownloadManager時發生?

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(soundURL)); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); 
    deleteIfFileExist(filePath); 
    request.setDestinationInExternalFilesDir(context, SubPath, SndName); 
    return manager.enqueue(request); 

它工作正常,但我在面料看到一些用戶報告崩潰:

Fatal Exception: java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads 
    at android.content.ContentResolver.insert(ContentResolver.java:882) 
    at android.app.DownloadManager.enqueue(DownloadManager.java:904) 

我搜索一下,發現的地方,因爲他們DownloadManger是禁用。但我在android設備上看到android版本是4,他們沒有能力禁用它。任何人都可以幫助我爲什麼會發生這種錯誤?

+2

'soundURL'是什麼? –

+0

@VladMatvienko:我的下載網址。它是我的主機中的一個文件。我說這對大多數用戶正常工作,只是其中一些報告崩潰 – Maryam

+0

好的,對不起,問題不在源,但在destenation網址 –

回答

0

無法直接激活/停用Download Manager,因爲它是系統應用程序,我們無法訪問它。

只剩下替代方法是將用戶重定向到Download Manager應用程序的信息頁面。

try { 
    //Open the specific App Info page: 
    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
    intent.setData(Uri.parse("package:" + "com.android.providers.downloads")); 
    startActivity(intent); 

} catch (ActivityNotFoundException e) { 
    e.printStackTrace(); 

    //Open the generic Apps page: 
    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); 
    startActivity(intent); 
} 
+0

那麼,爲什麼我的應用程序有這個錯誤? – Maryam

相關問題