社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  SushiHangover  »  全部回复
回复总数  1
7 年前
回复了 SushiHangover 创建的主题 » android应用连接mysql数据库的登录状态验证

把这些不同的答案应用到 Xamarin.Android ,您可以使用类和程序集级别的属性,而不是手动编辑 AndroidManifest.xml

当然需要互联网许可(duh..):

[assembly: UsesPermission(Android.Manifest.Permission.Internet)]

注意:通常程序集级属性会添加到 AssemblyInfo.cs 文件,但任何文件,在 using 高于 namespace 作品。

然后在应用程序子类(如果需要,可以创建一个)上添加 NetworkSecurityConfig 指的是 Resources/xml/ZZZZ.xml 文件:

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, NetworkSecurityConfig = "@xml/network_security_config")]
#else
[Application(AllowBackup = true, Debuggable = false, NetworkSecurityConfig = "@xml/network_security_config"))]
#endif
public class App : Application
{
    public App(IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer) { }
    public App() { }

    public override void OnCreate()
    {
        base.OnCreate();
    }
}

在中创建文件 Resources/xml 文件夹(创建 xml 文件夹(如果需要)。

例子 xml/network_security_config 文件,根据需要调整(参见其他答案)

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">www.example.com</domain>
          <domain includeSubdomains="true">notsecure.com</domain>
          <domain includeSubdomains="false">xxx.xxx.xxx</domain>
    </domain-config>
</network-security-config>

您也可以使用 UsesCleartextTraffic 上的参数 ApplicationAttribute :

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, UsesCleartextTraffic = true)]
#else
[Application(AllowBackup = true, Debuggable = false, UsesCleartextTraffic = true))]
#endif