问题
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.
回答1:
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>
回答2:
If your app targets Android 9 or higher, the isCleartextTrafficPermitted()
method returns false by default.
If your app needs to enable cleartext for specific domains, you must explicitly set cleartextTrafficPermitted to true for those domains in your app's Network Security Configuration.
Framework Security changes in Android 9 that improve your app's security
来源:https://stackoverflow.com/questions/55534046/data-not-showing-on-android-pie-9-0