【问题标题】:download HTTP/HTTPS URIs with DownloadManager使用 DownloadManager 下载 HTTP/HTTPS URI
【发布时间】:2015-02-10 03:41:45
【问题描述】:

我用谷歌搜索并找到了一些关于此的内容。但这无济于事。

安卓版本: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 com.souyidai.investment.android.service.DownloadService@4344e5e0 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;
    }

有什么想法吗?

【问题讨论】:

    标签: android https


    【解决方案1】:

    我也遇到了同样的问题。出于某种原因,我的网址在“https”之前有一种空格。在 url 字符串上使用trim() 解决了这个问题。

    【讨论】:

    • 我们有同样的问题。
    • @EIYeante 在 Galaxy S4 上同样的问题,但是 trim() 不能解决问题...请帮助
    【解决方案2】:

    这对我有用:

    addAndroidDownloads: {
              mediaScannable: true, // these two lines resolve the crash on first download
              mime: 'image/*', // define mime type also
    

    【讨论】:

    • 你到底是在哪里配置的?
    • @cmptrwizard 在 RN 应用程序中的包调用函数配置中 [NOT FOR ANDROID NATIVE]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多