1
我使用Google搜索並找到了一些相關信息。但是這並沒有幫助。使用DownloadManager下載HTTP/HTTPS URI
的Android版本:4.0+
這裏是我的代碼:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
而且我的網址是https://static.test.com/downloads/xxx.apk
方案爲https,但我仍然得到一個錯誤:
02-10 11:18:23.710 E/AndroidRuntime(7550): java.lang.RuntimeException: Unable to start service [email protected] with Intent { act=download_with_download_manager cmp=com.souyidai.investment.android/.service.DownloadService (has extras) }: java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: https://static.test.com/downloads/xxx.apk
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2711)
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.app.ActivityThread.access$2100(ActivityThread.java:141)
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1299)
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.os.Handler.dispatchMessage(Handler.java:102)
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.os.Looper.loop(Looper.java:136)
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.app.ActivityThread.main(ActivityThread.java:5047)
02-10 11:18:23.710 E/AndroidRuntime(7550): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 11:18:23.710 E/AndroidRuntime(7550): at java.lang.reflect.Method.invoke(Method.java:515)
02-10 11:18:23.710 E/AndroidRuntime(7550): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
02-10 11:18:23.710 E/AndroidRuntime(7550): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
02-10 11:18:23.710 E/AndroidRuntime(7550): at dalvik.system.NativeStart.main(Native Method)
02-10 11:18:23.710 E/AndroidRuntime(7550): Caused by: java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: https://static.test.com/downloads/xxx.apk
02-10 11:18:23.710 E/AndroidRuntime(7550): at android.app.DownloadManager$Request.<init>(DownloadManager.java:642)
02-10 11:18:23.710 E/AndroidRuntime(7550): at com.souyidai.investment.android.service.DownloadService.onStartCommand(DownloadService.java:114)
這裏的DownloadManager.Request代碼:
public Request(Uri uri) {
if (uri == null) {
throw new NullPointerException();
}
String scheme = uri.getScheme();
if (scheme == null || (!scheme.equals("http") && !scheme.equals("https"))) {
throw new IllegalArgumentException("Can only download HTTP/HTTPS URIs: " + uri);
}
mUri = uri;
}
任何想法?
我們有同樣的問題。 – 2015-09-18 01:58:53
@EIYeante 同樣的問題在Galaxy S4上,但修剪()沒有解決問題... PLease幫助 – Balflear 2017-06-09 14:35:18