[Android development] network permission application

  1. Create a security profile
    1. Create the xml/network-security-config file in the res folder
    2. Increase the cleartextTrafficPermitted property
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted='true'/>
</network-security-config>
  1. Add a security profile
    1. Application statement in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.webapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.WebApplication"
        android:networkSecurityConfig="@xml/network_security_config">
        <!--添加安全配置文件-->
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <!--开启INTERNET权限-->
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Guess you like

Origin blog.csdn.net/weixin_42020386/article/details/113091233