android - android pie 上的 Retrofit2 响应为空

标签 android null response android-9.0-pie

在 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/

相关文章:

sql - 在 t-SQL 中将值与 NULL 进行比较

c# - Http 请求状态代码 405 ReasonPhrase : '' Youtube APi

java - Mapbox Android SDK - 致命信号 11 (SIGSEGV)

android - java.lang.RuntimeException:无法启动 Activity ComponentInfo_Error膨胀类android.support.design.widget.NavigationView

java - 将目标 sdk 更新到 29 后导入已弃用的警告

Java DOM 解析器返回空文档

arrays - 使用数组内容时 Swift nil 合并

http - 403响应可以吗?

c# - WCF 客户端如何使用多部分/相关的 Java Web 服务响应?

python - Kivy 禁用屏幕超时