数据未显示在Android Pie 9.0上

问题描述:

将手机从Android Oreo 8.0更新为Android Pie 9.0之后,我不再可以使用HttpUrlConnection从MySQL数据库获取数据。

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.

我尝试使用模拟器Android Oreo 8.0并显示数据。但是,当我尝试使用模拟器Android Pie 9.0时,不会显示数据。请帮助我。

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.

我最近在Android 9上遇到了同样的问题,但是我不得不在不同的屏幕上使用一些URL。因此,我向清单中添加了android:usesCleartextTraffic = true并成功了,但是我们不想为此牺牲整个应用程序的安全性。因此,解决方法是将链接从HTTP更改为https。但是,如果您只需要使用http与您的应用进行通信,那么这就是您的解决方案。

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"

将其添加到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>