Android Studio:ping URL 时出错:http://google.com不允许到 google.com 的明文 HTTP 流量

问题描述

我正在使用 Facebook Audience Network AdMob 测试 mediation 广告。我正在使用他们文档中提到的 Mediation Test Suite 对其进行测试。

当我尝试从中介测试套件中的 facebook 广告加载广告时出现此错误(从 admob 加载广告工作正常)。

Error while pinging URL: http://google.com. Cleartext HTTP traffic to google.com not permitted
Ad Failed to load : 0

SO 中提出了很多类似的问题,但没有一个我有用。 这与 Network security configuration 有关。根据他们的文档,我在我的应用程序中添加了所有必要的文件。它们是:

res/xml/network_security_config.xml

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

AndroidManifest.xml

<application
    ...
    android:networkSecurityConfig="@xml/network_security_config">
    ...
</application>

我也试过在清单文件中使用 android:usesCleartextTraffic="true" 但后来我得到这个错误

Ad Failed to load : 0
Received non-success response code 302 from pinging URL: http://google.com

我已经按照 SO 上的一些答案中的建议卸载并安装了我的应用,但仍然无法正常工作。

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)