androidhttpurlconnectionandroid-8.0-oreoandroid-9.0-pieandroid-8.1-oreo

Data not showing on Android Pie 9.0


After I updated my phone from Android Oreo 8.0 to Android Pie 9.0, I no longer can get data from MySQL database using HttpUrlConnection.

I try with emulator Android Oreo 8.0 and the data is displayed. However, when I try with emulator Android Pie 9.0, the data is not displayed. Please help me.


Solution

  • I Recently had the same issue for Android 9, but I had to use some URLs for different screens. So I added android:usesCleartextTraffic="true" to Manifest and it worked, but we didn't want to compromise the security of the whole app for this. So the fix was in changing links from HTTP to https.But if you had to use only http to communicate with your app then here is your solution.

    android:networkSecurityConfig="@xml/security_config"
    

    Add this in the Xml

    <network-security-config>
    <base-config cleartextTrafficPermitted="true"/>
    <debug-overrides>
    <trust-anchors>
    <certificates src="system" />
    <certificates src="user" />
    </trust-anchors>
    </debug-overrides>
    </network-security-config>