Retrofit2 ответ нулевой на андроид пирог - PullRequest
1 голос
/ 24 марта 2019

На Android пирог я получаю нулевой ответ на запрос retrofit2. Тот же код работает на всех предыдущих устройствах Android. я добавил android: usedCleartextTraffic = "true" в манифесте, это исправило проблему http-соединения, но я не получаю ожидаемый ответ во всех других версиях androided, ответ ожидается, но не в виде пирога. поэтому, пожалуйста, помогите спасибо заранее

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

MainActivity

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 {

код выше работает нормально на всех устройствах Android, кроме пирога. Пирог получает нулевой ответ

1 Ответ

1 голос
/ 09 апреля 2019

Перейти к 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">

Надеюсь, это сработает для вас.

...