android pie上的Retrofit2响应为空 [英] Retrofit2 response null on android pie

查看:86
本文介绍了android pie上的Retrofit2响应为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 android pie 上,我收到了对 Retrofit2 请求的空响应.相同的代码适用于所有以前的 android 设备.我在清单中添加了 android:usesCleartextTraffic="true" ,它修复了 http 连接的问题,但在所有其他 androided 版本中我没有得到预期的响应,响应是预期的,但不是馅饼.所以请提前帮助谢谢

On android pie i am getting null response for retrofit2 request. Same code is working on all previous android devices. i have added android:usesCleartextTraffic="true" in manifest its fixed the issue of http connection but i am not getting response as expected in all other androided version the response is expected but not in pie. so please help thanks in advance

  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">

主活动

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 设备中都可以正常工作.派得到空响应

above code is working fine in all android devices except pie. Pie getting null response

推荐答案

转到应用程序标签中的 Manifest.xml.如下添加这两行.

Go to Manifest.xml in application tag. Add these two lines as given below.

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 pie上的Retrofit2响应为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆