Android Studio-无法调用API,因为;指定了网络安全配置,使用平台默认值;错误日志
我正在尝试构建一个转换货币的应用程序。我使用公共API访问货币兑换功能。调试代码时,由于此网络安全错误,我无法查看JSON接收的对象。我在这里查看了其他帖子,并试图通过在AndriodManifest.xml文件中包含安卓:usesCleartextTraffic=“true”和使用权限安卓:name=“android.permission.ACCESS_NETWORK_STATE”来修复它。这是调试输出的图像: 这是我的代码文件 AndriodManifest.xml:Android Studio-无法调用API,因为;指定了网络安全配置,使用平台默认值;错误日志,android,android-studio,retrofit2,android-debug,android-network-security-config,Android,Android Studio,Retrofit2,Android Debug,Android Network Security Config,我正在尝试构建一个转换货币的应用程序。我使用公共API访问货币兑换功能。调试代码时,由于此网络安全错误,我无法查看JSON接收的对象。我在这里查看了其他帖子,并试图通过在AndriodManifest.xml文件中包含安卓:usesCleartextTraffic=“true”和使用权限安卓:name=“android.permission.ACCESS_NETWORK_STATE”来修复它。这是调试输出的图像: 这是我的代码文件 AndriodManifest.xml: <?xml ve
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.currencyconversion">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.CurrencyConversion"
android:usesCleartextTraffic="true"
>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
www.interface.java:
package com.example.currencyconversion.Retrofit;
import com.google.gson.JsonObject;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface RetrofitInterface {
@GET("v6/4API-KEY/latest/{currency}")
Call<JsonObject> getExchangeCurrency(@Path("currency") String currency);
}
package com.example.currencyconversion.reformation;
导入com.google.gson.JsonObject;
2.电话;;
导入文件2.http.GET;
导入2.http.Path;
公共接口改造接口{
@获取(“v6/4API-KEY/latest/{currency}”)
调用getExchangeCurrency(@Path(“currency”)字符串currency);
}
@Serializable(“name”) //annotation
String Name;
标题中的消息不是错误。
package com.example.currencyconversion.Retrofit;
import com.google.gson.JsonObject;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface RetrofitInterface {
@GET("v6/4API-KEY/latest/{currency}")
Call<JsonObject> getExchangeCurrency(@Path("currency") String currency);
}
@Serializable(“name”) //annotation
String Name;