myCall.enqueue(new Callback()){.....}没有给出任何回复

时间:2018-06-14 05:37:11

标签: android retrofit2 okhttp3

我正在我的android工作室制作一个adforest分类相似的应用程序         下面是启动屏幕活动,当我点击应用程序图标时首先执行,但之后下一个活动没有打开...启动屏幕上的进度条一直在旋转,但它没有打开下一个活动!!

SplashScreen.java

public class SplashScreen extends AppCompatActivity {

                Activity activity;
                SettingsMain setting;
                JSONObject jsonObjectSetting;

                boolean isRTL = false;

                public static JSONObject jsonObjectAppRating, jsonObjectAppShare;

                public static boolean gmap_has_countries = false, app_show_languages = false;
                public static JSONArray app_languages;
                public static String languagePopupTitle, languagePopupClose, gmap_countries;

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_splash_screen);
                    Configuration configuration = getResources().getConfiguration();
                    configuration.fontScale = (float) 1; //0.85 small size, 1 normal size, 1,15 big etc

                    DisplayMetrics metrics = new DisplayMetrics();
                    getWindowManager().getDefaultDisplay().getMetrics(metrics);
                    metrics.scaledDensity = configuration.fontScale * metrics.density;
                    getBaseContext().getResources().updateConfiguration(configuration, metrics);

                    activity = this;
                    setting = new SettingsMain(this);


                    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
                    if (!prefs.getBoolean("firstTime", false)) {

                        setting.setUserLogin("0");

                        SharedPreferences.Editor editor = prefs.edit();
                        editor.putBoolean("firstTime", true);
                        editor.apply();
                    }

                    if (getSupportActionBar() != null) {
                        getSupportActionBar().hide();

                    }

                    try {
                        PackageInfo info = getPackageManager().getPackageInfo(
                                "com.call4site.nearhaat",
                                PackageManager.GET_SIGNATURES);
                        for (Signature signature : info.signatures) {
                            MessageDigest md = MessageDigest.getInstance("SHA1");
                            md.update(signature.toByteArray());
                            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));

                        }
                    } catch (NoSuchAlgorithmException e)
                    {
                         e.printStackTrace();
                    }
                    catch (PackageManager.NameNotFoundException e)
                    {
                        e.printStackTrace();

                    }

                    if (SettingsMain.isConnectingToInternet(this)) {

                        adforest_getSettings(this);

                    } else {
                        AlertDialog.Builder alert = new AlertDialog.Builder(SplashScreen.this);
                        alert.setTitle(setting.getAlertDialogTitle("error"));
                        alert.setCancelable(false);
                        alert.setMessage(setting.getAlertDialogMessage("internetMessage"));
                        alert.setPositiveButton(setting.getAlertOkText(), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                dialog.dismiss();
                                SplashScreen.this.recreate();
                            }
                        });
                        alert.show();
                    }
                }

                public void adforest_getSettings(final Context context) {

                    RestService restService =
                            UrlController.createService(RestService.class);

                    Call<ResponseBody> myCall = restService.getSettings(UrlController.AddHeaders(this));

                    myCall.enqueue(new Callback<ResponseBody>() { 
                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> responseObj) {
                            try {
                                if (responseObj.isSuccessful()) {
                                    Log.d("info settings Responce", "" + responseObj.toString());

                                    JSONObject response = new JSONObject(responseObj.body().string());
                                    Log.d("info settings object", "" + response.getJSONObject("data"));
                                    if (response.getBoolean("success")) {
                                        jsonObjectSetting = response.getJSONObject("data");

                                        setting.setMainColor(jsonObjectSetting.getString("main_color"));

                                        isRTL = jsonObjectSetting.getBoolean("is_rtl");
                                        setting.setRTL(isRTL);
                                        setting.setAlertDialogTitle("error", jsonObjectSetting.getJSONObject("internet_dialog").getString("title"));
                                        setting.setAlertDialogMessage("internetMessage", jsonObjectSetting.getJSONObject("internet_dialog").getString("text"));
                                        setting.setAlertOkText(jsonObjectSetting.getJSONObject("internet_dialog").getString("ok_btn"));
                                        setting.setAlertCancelText(jsonObjectSetting.getJSONObject("internet_dialog").getString("cancel_btn"));

                                        setting.setAlertDialogTitle("info", jsonObjectSetting.getJSONObject("alert_dialog").getString("title"));
                                        setting.setAlertDialogMessage("confirmMessage", jsonObjectSetting.getJSONObject("alert_dialog").getString("message"));

                                        setting.setAlertDialogMessage("waitMessage", jsonObjectSetting.getString("message"));

                                        setting.setAlertDialogMessage("search", jsonObjectSetting.getJSONObject("search").getString("text"));
                                        setting.setAlertDialogMessage("catId", jsonObjectSetting.getString("cat_input"));
                                        setting.setAlertDialogMessage("location_type", jsonObjectSetting.getString("location_type"));
                                        setting.setAlertDialogMessage("gmap_lang", jsonObjectSetting.getString("gmap_lang"));
                                        setting.setGoogleButn(jsonObjectSetting.getJSONObject("registerBtn_show").getBoolean("google"));
                                        setting.setfbButn(jsonObjectSetting.getJSONObject("registerBtn_show").getBoolean("facebook"));

                                        JSONObject alertDialog = jsonObjectSetting.getJSONObject("dialog").getJSONObject("confirmation");
                                        setting.setGenericAlertTitle(alertDialog.getString("title"));
                                        setting.setGenericAlertMessage(alertDialog.getString("text"));
                                        setting.setGenericAlertOkText(alertDialog.getString("btn_ok"));
                                        setting.setGenericAlertCancelText(alertDialog.getString("btn_no"));

                                        setting.isAppOpen(jsonObjectSetting.getBoolean("is_app_open"));
                                        setting.checkOpen(jsonObjectSetting.getBoolean("is_app_open"));
                                        setting.setGuestImage(jsonObjectSetting.getString("guest_image"));

                                        JSONObject jsonObjectLocationPopup = jsonObjectSetting.getJSONObject("location_popup");
                                        Log.d("info location_popup obj", "" + jsonObjectLocationPopup);
                                        setting.setLocationSliderNumber(jsonObjectLocationPopup.getInt("slider_number"));
                                        setting.setLocationSliderStep(jsonObjectLocationPopup.getInt("slider_step"));
                                        setting.setLocationText(jsonObjectLocationPopup.getString("text"));
                                        setting.setLocationBtnSubmit(jsonObjectLocationPopup.getString("btn_submit"));
                                        setting.setLocationBtnClear(jsonObjectLocationPopup.getString("btn_clear"));

                                        JSONObject jsonObjectLocationSettings = jsonObjectSetting.getJSONObject("gps_popup");
                                        setting.setShowNearby(jsonObjectSetting.getBoolean("show_nearby"));
                                        Log.d("info gps_popup obj", "" + jsonObjectLocationSettings);
                                        setting.setGpsTitle(jsonObjectLocationSettings.getString("title"));
                                        setting.setGpsText(jsonObjectLocationSettings.getString("text"));
                                        setting.setGpsConfirm(jsonObjectLocationSettings.getString("btn_confirm"));
                                        setting.setGpsCancel(jsonObjectLocationSettings.getString("btn_cancel"));

                                        setting.setAdsPositionSorter(jsonObjectSetting.getBoolean("ads_position_sorter"));

                                        setting.setBannerShow(false);
                                        setting.setAdsPosition("");
                                        setting.setBannerAdsId("");
                                        setting.setInterstitalShow(false);
                                        setting.setAdsInitialTime("");
                                        setting.setAdsDisplayTime("");
                                        setting.setInterstitialAdsId("");

                                        setting.setNotificationTitle("");
                                        setting.setNotificationMessage("");
                                        setting.setNotificationTitle("");

                                        if (setting.getAppOpen()) {
                                            setting.setNoLoginMessage(jsonObjectSetting.getString("notLogin_msg"));
                                        }

                                        setting.setFeaturedScrollEnable(jsonObjectSetting.getBoolean("featured_scroll_enabled"));
                                        if (setting.isFeaturedScrollEnable()) {
                                            Log.d("info setting AutoScroll", jsonObjectSetting.getJSONObject("featured_scroll").toString());
                                            setting.setFeaturedScroolDuration(jsonObjectSetting.getJSONObject("featured_scroll").getInt("duration"));
                                            setting.setFeaturedScroolLoop(jsonObjectSetting.getJSONObject("featured_scroll").getInt("loop"));
                                        }

                                        jsonObjectAppRating = jsonObjectSetting.getJSONObject("app_rating");
                                        jsonObjectAppShare = jsonObjectSetting.getJSONObject("app_share");

                                        gmap_has_countries = jsonObjectSetting.getBoolean("gmap_has_countries");
                                        if (gmap_has_countries) {
                                            gmap_countries = jsonObjectSetting.getString("gmap_countries");
                                        }
                                        app_show_languages = jsonObjectSetting.getBoolean("app_show_languages");

                                        if (app_show_languages) {
                                            languagePopupTitle = jsonObjectSetting.getString("app_text_title");
                                            languagePopupClose = jsonObjectSetting.getString("app_text_close");
                                            app_languages = jsonObjectSetting.getJSONArray("app_languages");

                                        }

                                        final Handler handler = new Handler();
                                        handler.postDelayed(new Runnable() {
                                            @Override
                                            public void run() {
                                                //Do something after 100ms

                                                if (setting.getUserLogin().equals("0")) {
                                                    SplashScreen.this.finish();
                                                    if (setting.isLanguageChanged()) {
                                                        if (isRTL)
                                                            updateViews("ur");
                                                        else {
                                                            updateViews("en");
                                                        }
                                                    }
                                                    Intent intent = new Intent(SplashScreen.this, MainActivity.class);
                                                    startActivity(intent);
                                                    overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                                                } else {
                                                    SplashScreen.this.finish();
                                                    if (setting.isLanguageChanged()) {
                                                        if (isRTL)
                                                            updateViews("ur");
                                                        else {
                                                            updateViews("en");
                                                        }
                                                    }

                                                    setting.isAppOpen(false);
                                                    Intent intent = new Intent(SplashScreen.this, HomeActivity.class);
                                                    startActivity(intent);
                                                    overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                                                }

                                                if (app_show_languages && !setting.isLanguageChanged()) {
                                                    if (setting.getLanguageRtl()) {
                                                        updateViews("ur");
                                                    } else {
                                                        updateViews("en");
                                                    }
                                                }
                                            }
                                        }, 2000);
                                    } else {
                                        Toast.makeText(activity, response.get("message").toString(), Toast.LENGTH_SHORT).show();
                                    }
                                }

                            }
                            catch (JSONException e)
                            {
                                e.printStackTrace();
                            }
                            catch (IOException e) {     

                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {

                            Log.d("info settings error", String.valueOf(t));
                            Log.d("info settings error", String.valueOf(t.getMessage() + t.getCause() + t.fillInStackTrace()));
                        }
                    });
                }

                @Override
                protected void attachBaseContext(Context base) {
                    super.attachBaseContext(LocaleHelper.onAttach(base));
                }

                private void updateViews(String languageCode) {
                    LocaleHelper.setLocale(this, languageCode);
                }
            }

这是用于调用改装api的UrlController java类:

UrlController.java

            public class UrlController {
                    static OkHttpClient okHttpClient = new OkHttpClient.Builder()
                            .connectTimeout(5, TimeUnit.MINUTES)
                            .writeTimeout(5, TimeUnit.MINUTES)
                            .readTimeout(5, TimeUnit.MINUTES)
                            .build();
                private static String Purchase_code = "************************";
                private static String Custom_Security = "***********************";

                private static String url = "null";
                private static String Base_URL = "https://yourdomain.co.in/demo/";
                private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
                private static Retrofit.Builder builder = new Retrofit.Builder()
                                .baseUrl(Base_URL)
                                .client(okHttpClient)
                                .addConverterFactory(GsonConverterFactory.create());

                private static Retrofit retrofit = builder.build();

                public static <S> S createService(Class<S> serviceClass)
                {
                    url = retrofit.baseUrl().toString();
                    return retrofit.create(serviceClass);
                }

                public static <S> S createService(
                        Class<S> serviceClass, String username, String password, Context context)
                {
                    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {
                        String authToken = Credentials.basic(username, password);

                        return createService(serviceClass, authToken, context);
                    }

                    return createService(serviceClass, null, null, context);
                }

                public static <S> S createService(
                        Class<S> serviceClass, final String authToken, Context context)
                {
                    if (!TextUtils.isEmpty(authToken)) {
                        AuthenticationInterceptor interceptor = new AuthenticationInterceptor(authToken, context);


                        if (!httpClient.interceptors().contains(interceptor))
                        {
                            httpClient.addInterceptor(interceptor);

                            builder.client(httpClient.build());

                            retrofit = builder.build();

                        }

                    }

                    return retrofit.create(serviceClass);
                }

                public static Map<String, String> AddHeaders(Context context) {
                    Map<String, String> map = new HashMap<>();
                    if (SettingsMain.isSocial(context)) {
                        map.put("AdForest-Login-Type", "social");
                    }

                    map.put("Purchase-Code", Purchase_code);
                    map.put("custom-security", Custom_Security);
                    map.put("Adforest-Request-From", "android");
                    map.put("Adforest-Lang-Locale", SettingsMain.getLanguageCode());
                    map.put("Content-Type", "application/json");
                    map.put("Cache-Control", "max-age=640000");
                    return map;
                }

                public static Map<String, String> UploadImageAddHeaders(Context context) {
                    Map<String, String> map = new HashMap<>();
                    if (SettingsMain.isSocial(context)) {
                        map.put("AdForest-Login-Type", "social");
                    }

                    map.put("Purchase-Code", Purchase_code);
                    map.put("custom-security", Custom_Security);
                    map.put("Adforest-Lang-Locale", SettingsMain.getLanguageCode());
                    map.put("Adforest-Request-From", "android");
                    map.put("Cache-Control", "max-age=640000");
                    return map;
                }
            }


        when it executes:

        myCall.enqueue(new Callback() 
         {

public void onResponse(Call<ResponseBody> call, Response<ResponseBody> responseObj) 
  {

        //some code here

  } );

  @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) 
            {
              //some code here
            }






      It does not executes either the on response method or on Failure method. No error or exception in catch block. In android studio logcat debug mode it shows : 

D / WindowClient:从mViews中删除:android.widget.LinearLayout {a73a5de V.E ...... ......我。 0,0-580,115},这= android.view.WindowManagerGlobal@eeef6d7 我不明白它背后的问题...这个调试消息是由于下一个活动没有打开或由于其他东西而发生的原因?     我被困在这里......没有找到任何方法继续前进!!

0 个答案:

没有答案