Data not showing on Android Pie 9.0

☆樱花仙子☆ 提交于 2019-12-11 12:03:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!