安卓开发之获取网络请求权限(Access to network request permission developed by Android)

首先,在res目录下新建一个xml文件夹

新建network_security_config.xml文件、

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

第二步在AndroidManifest.xml中添加如下代码

添加代码为下列代码中放大的部分

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapplication">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
            android:allowBackup="true"
            android:icon="@mipmap/bg"
            android:label="随处"
            android:networkSecurityConfig="@xml/network_security_config"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.MyApplication">
        <activity
                android:name=".about"
                android:exported="true"/>
        <activity
                android:name=".SplashActivity"
                android:exported="true">
        </activity>
        <activity
                android:name=".MainActivity"
                android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
                android:name=".webview4"
                android:exported="true"/>
        <activity
                android:name=".webview3"
                android:exported="true"/>
        <activity
                android:name=".webview2"
                android:exported="true"/>
        <activity
                android:name=".webview"
                android:exported="true"/>
        <activity
                android:name=".VATUU"
                android:exported="true"/>
    </application>

</manifest>

这样就可以获取网络访问权限了

————————

First, create a new XML folder in the res directory

新建network_security_config.xml文件、

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

The second step is at Android manifest Add the following code to XML

Add the code as the enlarged part of the following code

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapplication">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
            android:allowBackup="true"
            android:icon="@mipmap/bg"
            android:label="随处"
            android:networkSecurityConfig="@xml/network_security_config"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.MyApplication">
        <activity
                android:name=".about"
                android:exported="true"/>
        <activity
                android:name=".SplashActivity"
                android:exported="true">
        </activity>
        <activity
                android:name=".MainActivity"
                android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
                android:name=".webview4"
                android:exported="true"/>
        <activity
                android:name=".webview3"
                android:exported="true"/>
        <activity
                android:name=".webview2"
                android:exported="true"/>
        <activity
                android:name=".webview"
                android:exported="true"/>
        <activity
                android:name=".VATUU"
                android:exported="true"/>
    </application>

</manifest>

In this way, you can obtain network access