猿问

Android Glide 添加了 网络限权还是无法加载图片

if (mContext != null) {
    Glide.with(mContext)
            .load("http://res.lgdsunday.club/poster-1.png")
            .into(viewHolder.ivIcon);

打包以后手机上显示正常 但是在api29虚拟机上 显示不出来图片 网络限权也添加了

<uses-permission android:name="android.permission.INTERNET" />

W/Glide: Load failed for http://res.lgdsunday.club/poster-1.png with size [353x353]

    class com.bumptech.glide.load.engine.GlideException: Failed to load resource

    There was 1 cause:

    java.io.IOException(Cleartext HTTP traffic to res.lgdsunday.club not permitted)

     call GlideException#logRootCauses(String) for more detail

      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE

    There was 1 cause:

    java.io.IOException(Cleartext HTTP traffic to res.lgdsunday.club not permitted)

     call GlideException#logRootCauses(String) for more detail

        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed

    There was 1 cause:

    java.io.IOException(Cleartext HTTP traffic to res.lgdsunday.club not permitted)

     call GlideException#logRootCauses(String) for more detail

          Cause (1 of 1): class java.io.IOException: Cleartext HTTP traffic to res.lgdsunday.club not permitted

I/Glide: Root cause (1 of 1)

    java.io.IOException: Cleartext HTTP traffic to res.lgdsunday.club not permitted

        at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:124)

        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)

        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)

        at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:104)

        at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)

        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)

        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)

        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)

        at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:65)

        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)

        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)

        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:309)

        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)

        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

        at java.lang.Thread.run(Thread.java:919)

        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)


qq_Heucheleisir_0
浏览 12463回答 3
3回答

晓黑黑杂

android9.0系统默认禁止http协议,即禁止明文传输,必须使用https来通讯;而app中所使用的图片和某些地方用的正好是http协议的方式。在Manifest的application中加入以下语句即可android:usesCleartextTraffic="true"
随时随地看视频慕课网APP

相关分类

Android
我要回答