解決 Android p(9.0)系統不兼容http 通信問題

前言

1、測試機型: 華爲p20 pro

                          EMUI 9.0.0

                          Android 9

2、頁面報錯問題「Cleartext HTTP traffic to xxx.xxx.xxx.xx not permitted」,如圖:

 

解決方法:

1、在項目的res目錄下創建xml文件夾,並在裏面創建一個「.xml」的文件,文件內容如下,可直接複製黏貼:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

2、打開「AndroidManifest.xml」文件,並且在標籤「application」中添加如下代碼:

 android:networkSecurityConfig="@xml/network_config"

3、最後重新編譯項目測試即可。

 

如有疑問請留言,如解決了道友的問題給個贊。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章