1
  • 1153952789488054272  评论     打赏       拉大锯
    • <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.eryu">
          <!--连接网络-->
          <uses-permission android:name="android.permission.INTERNET" />
          <!--用于管理监听网络状态的变化-->
          <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
          <!--用于管理监听网络状态的变化-->
          <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
          <!--用于管理监听网络状态的变化-->
          <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
          <!--获取电话的状态,在打电话的时候暂停播放-->
          <uses-permission android:name="android.permission.READ_PHONE_STATE" />
          <!--target >=28 需要设置此权限 -->
          <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
      

      是这里吗?

      1260137563809759232  评论     打赏       977
      • <application
            android:allowBackup="true"
            android:networkSecurityConfig="@xml/network_security_config"
            android:name=".base.BaseApplication"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
        
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        

        这个也添加了

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

        这个也加了但是还是报错

        2020-05-13 18:17:37.446 26937-26937/com.example.eryu E/MainActivity: error code -- 604error msg ==> 网络请求失败
        


        1260137563809759232  评论     打赏       977
        • 拉大锯  回复 @977
          访问网络的权限配置了吗?
          拉大锯 2020-05-13 18:34   回复 1153952789488054272
        • 977  回复 @拉大锯
          老大,您看一下
          977 2020-05-13 18:43   回复 1260137563809759232
        • 拉大锯  回复 @977
          你给我一份Log吧,发QQ里。
          拉大锯 2020-05-13 19:13   回复 1153952789488054272
      • 应按说是配置允许明文访问


        你的网络请求604了


        说明网路请求错误:


        检查以下问题:


        1、是否有在清单文件上声明权限


        2、是否有允许明文访问,从api27以后,不直接支持http,默认支持https


        如何配置允许明文访问呢?


        参考 这篇文章


        https://www.sunofbeach.net/s/1200632106011709440



        在AndroidManifest里application里加了android:networkSecurityConfig="@xml/network_security_config"


        在res目录下创建一个xml文件夹,创建一个文件叫做network_security_config.xml


        内容如下:


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


        具体域名可以看一下Log是不是这个。



        1153952789488054272  评论     打赏       拉大锯
        • 977  回复 @拉大锯
          你看一下,我刚配置了但是还是出错误
          977 2020-05-13 18:18   回复 1260137563809759232
      相关问题
      2019-10-13 04:29 810 2
      你可长丶心吧 · 喜马拉雅
      2019-11-15 22:54 598 2
      2019-12-23 23:31 1303 2
      2020-01-06 04:50 1484 2