Glide FileNotFoundException: No content provider when loading images from internet

后端 未结 3 824
无人及你
无人及你 2021-02-19 03:14

I made my own rest api and now it just has endpoint where I show some images. Here how it looks in spring boot application

@GetMapping(\"/image/{name:.+}\")
             


        
相关标签:
3条回答
  • 2021-02-19 03:48

    If you are targeting API 28 on and the issue appears on Android 9 and the URL starting with http your issue is with cleartext traffic as mentioned here in Network security configuration

    Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

    ensure that all connections to are always done over HTTPS to protect sensitive traffic from hostile networks.

    If you want to Opt out of cleartext traffic

    Add this property on your application manifests only

    <application
     . 
     android:usesCleartextTraffic="true"
     .
    
     >
    
     </application>
    

    And if you want to have specific domains to have the rule

    Create file res/xml/network_security_config.xml

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">secure.example.com</domain>
    </domain-config>
    </network-security-config>
    

    AndroidManifest.xml -

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
        <uses-permission android:name="android.permission.INTERNET" />
        <application
            ...
            android:networkSecurityConfig="@xml/network_security_config"
            ...>
            ...
        </application>
    </manifest>
    
    0 讨论(0)
  • 2021-02-19 04:11

    Add to gradle annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

    0 讨论(0)
  • 2021-02-19 04:13

    in my case i just put my link inside string variable

    String link = "http://myipaddress/api/image/myimage.jpg";
    
    Glide.with(context).load(link).into(img);
    

    and problem solve!

    0 讨论(0)
提交回复
热议问题