android - 与新版本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);
//
解决方案
推荐阅读
- swift - "View Controller A unreachable because it has no entry points" error after adding a new View Controller B and changing it to initial view controller
- express - 为什么安装 Express 头盔后显示 x-powered-by 标头?
- c# - 在 MVC 中使用 JsonResult 类型格式化 json
- javascript - 如何获得本地存储来保存不同的购物车项目?
- vue.js - 变量状态未绑定
- bootstrap-4 - 引导网格行间距 cna 我使用实用程序类?
- java - 无法从文件加载 RSA 公钥(Java)
- c# - 如何在 linq 中使用 Select
- python-3.x - python 3.7.5:asyncio.get_event_loop 没有创建事件循环
- visual-studio-code - 您可以使用 VS Code 中的键盘在悬停弹出窗口中激活按钮吗?