Volley Not making request on latest version of Android

前端 未结 4 645
旧巷少年郎
旧巷少年郎 2020-12-10 08:59

I noticed my app wasn\'t working on Pixel 3. I went into android studio and emulated a few devices and noticed it is not working on any Android Pie (API 28) devices, but wor

4条回答
  •  余生分开走
    2020-12-10 09:25

    This is because starting with Android P, any network traffic between your app and insecure destinations must be explicitly whitelisted. See Protecting users with TLS by default in Android P.

    In your code, you're making a request to:

    http://hellapunk.com/listallshows.php?id=2018
    

    The http:// shows that the site is not secure. If you dig deeper into your LogCat you'll likely find a message such as:

    com.android.volley.NoConnectionError: java.io.IOException: Cleartext HTTP traffic to hellapunk.com not permitted
        at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:177)
        at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
        at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
     Caused by: java.io.IOException: Cleartext HTTP traffic to hellapunk.com not permitted
        at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
        at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:99)
        at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
        at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 
        at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87) 
    

    Attempting it myself, it doesn't appear that the site supports https connections, so in order to reach this particular server from your application, you would need to whitelist the hellapunk.com domain manually.

    In your resources directory, define an XML document for your network security configuration (e.g. res/xml/network_security_config.xml):

    network_security_config.xml:

    
    
        
            hellapunk.com
        
    
    

    Then, in your AndroidManifest.xml for your application, in the tag, add the attribute:

    You should then be allowed to make insecure requests to any domain specified within that file.

提交回复
热议问题