首页 > 解决方案 > 与新版本android没有连接

问题描述

大家好,我的android应用程序有问题。当我想使用 API 时会出现问题。问题出在新版本错误消息中:E/MainActivity: Pas de connexion internet...veuillez verifier votre connexion!javax.net.ssl.SSLHandshakeException: Handshake failed i use HTTPS

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //get the data and append to a list

    DatabaseHelp db = new DatabaseHelp(this);
    Cursor data = db.getData();
    ArrayList<String> listData = new ArrayList<>();
    while (data.moveToNext()) {
        //get the value from the database in column 1
        //then add it to the ArrayList
        listData.add(data.getString(1));
    }
    System.out.println("ffffffffffffffff" + listData);
    if (listData.isEmpty()) db.addData("me");
    LanguageHelper.loadLocale(this.getResources(), getSharedPreferences("Settings", MODE_PRIVATE));

    setContentView(R.layout.activity_main);

    // change la langue de titre
    //ActionBar actionbar =getSupportActionBar ();
    //actionbar.setTitle(getResources().getString(R.string.app_name));

    Toolbar bar = findViewById(R.id.toolbar);
    bar.setLogo(R.drawable.shield);
    context = getApplicationContext();
    password = findViewById(R.id.editTextPassword);
    button_login = findViewById(R.id.buttonLogin);
    spGlycemies = context.getSharedPreferences("glycemies", Context.MODE_PRIVATE);
    sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    edit = sp.edit();
    img_pass = findViewById(R.id.imageView);
    show = false;
    img_pass.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (show) {
                password.setTransformationMethod(null);
                img_pass.setImageResource(R.drawable.ic_visibility_black_24dp);
            } else {
                password.setTransformationMethod(new PasswordTransformationMethod());
                img_pass.setImageResource(R.drawable.ic_visibility_off_black_24dp);
            }
            show = !show;
        }
    });
    button_login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*Intent i = new Intent(MainActivity.this,WelcomeActivity.class);
            startActivity(i);*/
            login();
        }
    });
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    cache = new DiskBasedCache(getCacheDir(), 1024 * 1024);
    network = new BasicNetwork(new HurlStack());
    host = sp.getString("host_url", getString(R.string.host_adr));
    port = sp.getString("host_port", getString(R.string.host_port));
    url = host + ":" + port + getString(R.string.urlLogin);

}

private void login() {


    Timber.i(getString(R.string.sign));
    passwordError = false;
    intent = new Intent(this, WelcomeActivity.class);
    pass = password.getText().toString();
    RequestQueue queue = new RequestQueue(cache, network);
    queue.start();
    System.out.println(url + pass);
    updateAndroidSecurityProvider();
    JsonObjectRequest jsObjRequest = new JsonObjectRequest
        (Request.Method.GET, url + pass, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    patients = response.getJSONArray("patients");

                    if (patients != null) {
                        Timber.i("JSON patients object length : " + patients.length());
                    }

                    if (patients.length() >= 1 && patients.getJSONObject(0) != null) {
                        JSONObject patient = patients.getJSONObject(0);
                        connected = true;
                        edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);

                        id = patient.getString("id");
                        firstName = patient.getString("nom");
                        lastName = patient.getString("prenom");
                        if (!patient.isNull("sexe"))
                            sexe = patient.getString("sexe");
                        if (!patient.isNull("age"))
                            age = patient.getInt("age");
                        if (!patient.isNull("telephone"))
                            tel = patient.getString("telephone");

                        if (!patient.isNull("ratioPetitDej"))
                            rp = patient.getDouble("ratioPetitDej");
                        if (!patient.isNull("ratioDej"))
                            rd = patient.getDouble("ratioDej");
                        if (!patient.isNull("ratioColl"))
                            rc = patient.getDouble("ratioColl");
                        if (!patient.isNull("ratioDinnez"))
                            rdi = patient.getDouble("ratioDinnez");
                        if (!patient.isNull("IndiceSensibilite"))
                            is = patient.getDouble("IndiceSensibilite");
                        if (!patient.isNull("Objectif"))
                            obj = patient.getDouble("Objectif");

                        edit.putInt("count", c);
                        edit.putString("nom", firstName);
                        edit.putString("pren", lastName);
                        edit.putString("sexe", sexe);
                        edit.putInt("age", age);
                        edit.putString("tel", tel);
                        edit.putFloat("rp", (float) rp);
                        edit.putFloat("rd", (float) rd);
                        edit.putFloat("rc", (float) rc);
                        edit.putFloat("rdi", (float) rdi);
                        edit.putFloat("rp", (float) rp);
                        edit.putFloat("is", (float) is);
                        edit.putFloat("obj", (float) obj);
                        edit.putString("id", id);
                        edit.putString("pass", pass);

                        edit.commit();
                        startActivity(intent);
                    } else {
                        edit.putBoolean(getString(R.string.pref_previously_started), Boolean.FALSE);
                        edit.commit();
                    }

                } catch (JSONException e) {
                    Timber.e("JSON Error : " + e.getMessage());
                } catch (Exception e) {

                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Timber.e("Volly Error : " + error.toString());

                edit.putBoolean(getString(R.string.pref_previously_started), Boolean.FALSE);
                edit.commit();

                String message = null;

                if (error instanceof NetworkError) {
                    message = "Pas de connexion internet...veuillez verifier votre connexion!";
                } else if (error instanceof ServerError) {
                    message = "Serveur introuvable. veuillez reessayer après!!";
                } else if (error instanceof AuthFailureError) {
                    message = "Erreur d'authentification!";
                } else if (error instanceof ParseError) {
                    message = "Mot de passe incorrect!";
                    passwordError = true;
                } else if (error instanceof NoConnectionError) {
                    message = "Pas de connexion internet...veuillez verifier votre connexion!";
                } else if (error instanceof TimeoutError) {
                    message = "Délai de connection dépassé!...veuillez verifier votre connexion!";
                }



                CharSequence msg = message + "" + error.getMessage();

                showErrorAlert(MainActivity.this, message);

                Timber.e(msg.toString());
                  }
            }

        });

    MySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsObjRequest);

//

标签: androidandroid-volley

解决方案


推荐阅读