Дооснащение при неудаче в знак APK - PullRequest
0 голосов
/ 05 ноября 2019
if (checkPlayServices()) {
            HashMap<String, RequestBody> map = new HashMap<>();
            map.put(Constant.TYPE, ApiClient.makeTextRequestBody(String.valueOf(Constant.TYPE_STORE)));
            map.put(Constant.DEVICE_TYPE, ApiClient.makeTextRequestBody(Constant.ANDROID));

            Call<AppSetting> call = ApiClient.getClient().create(ApiInterface.class).getAppSettingDetail(map);

            call.enqueue(new Callback<AppSetting>() {
                @Override
                public void onResponse(Call<AppSetting> call, Response<AppSetting> response) {//AppSetting.java response api
                    Toast.makeText(MainActivity.this, String.valueOf(response.body()), Toast.LENGTH_LONG).show();
                    if (response.isSuccessful()) {
                        //   Toast.makeText(MainActivity.this, " onResponse: "+"response.successfully", Toast.LENGTH_LONG).show();
                        Utilities.printLog("MainActivity", "check app key --" + new Gson().toJson(response.body()));

                        if (response.body().isSuccess()) {
                            //     Toast.makeText(MainActivity.this, " onResponse: "+"response is successfully", Toast.LENGTH_LONG).show();
                            if (parseContent.parseAppSettingDetails(response)) {
                                if (PreferenceHelper.getPreferenceHelper(MainActivity.this).isForceUpdate() && checkVersionCode(response.body().getVersionCode())) {
                                    openUpdateAppDialog(response.body().isIsForceUpdate());
                                } else {
                                    /** option if user still login go to home else go to RegisterLoginActivity.java **/
                                    goToActivity();
                                }
                            }

                        } else {
                            Toast.makeText(MainActivity.this, response.message(), Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(MainActivity.this, response.message(), Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(Call<AppSetting> call, Throwable t) {
                   // Toast.makeText(MainActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
                    Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                    Log.d("Retrofit", "Retrofit: onResponse not called, onFailure called instead... ");
                    Log.d("Retrofit", t.getStackTrace().toString());
                    Log.d("Retrofit", t.getMessage());
                }
            });
        }

1 Ответ

0 голосов
/ 06 ноября 2019

Вы можете добавить setLenient к вашему GsonBuilder(), как показано ниже.

Gson gson = new GsonBuilder()
        .setLenient()
        .create();

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();

Примечание: Убедитесь, что у вас есть gson зависимость в вашем gradle.

implementation 'com.google.code.gson:gson:2.8.6'
...