在 android pie 上,我收到 retrofit2 请求的空响应。相同的代码适用于所有以前的 android 设备。我在 list 中添加了 android:usesCleartextTraffic="true"它修复了 http 连接的问题,但我没有像预期的那样在所有其他 android 版本中得到响应响应是预期的但不是在 pie 中。所以请提前致谢
Manifest.xml
<application
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/cabad_logo_new"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/cabad_logo_new_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
主要 Activity
RetrofitInterface jsonPostService =
ServiceGenerator.createService(RetrofitInterface.class,
"http://xxx.xxx.xxx.xxx:8080/");
Call<LoginResult> call = jsonPostService.postRawJSON(jsonObject);
call.enqueue(new Callback<LoginResult>() {
@Override
public void onResponse(Call<LoginResult> call,
Response<LoginResult> response) {
try {
以上代码在除 pie 之外的所有 android 设备上都运行良好。馅饼得到空响应
最佳答案
转到应用程序标记中的 Manifest.xml。 如下所示添加这两行。
android:usesCleartextTraffic="true"
tools:targetApi="m
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="m">
我希望它对你有用。
关于android - android pie 上的 Retrofit2 响应为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55323315/