我在Android上有一个登录系统,问题是有些手机可以识别自己的身份,而另一些则不能,但是没有错误报告。
private void LogUser() {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Please Wait ...");
dialog.show();
String email = this.Editemail.getText().toString().trim();
String password = this.Editpassword.getText().toString().trim();
apiInterface = ApiClient.getRetrofitInstance().create(ApiInterface.class);
Call<User> call = apiInterface.LogUser(email,password);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response)
{
if (response.body().getResponse().equals("ok"))
{
SaveSharedPreference.setLoggedIn(getApplicationContext(), true);
downloadCatalogue();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
dialog.dismiss();
}else if (response.body().getResponse().equals("failed"))
{
Toast.makeText(LoginActivity.this, "Email ou mot de passe ne correspond à aucun compte", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Toast.makeText(LoginActivity.this, "Echec d'authantification", Toast.LENGTH_SHORT);
dialog.dismiss();
}
});
}
答案 0 :(得分:0)
这是我的ApiClieny代码
public class ApiClient {
public static final String BASE_URL = "http://IP:port/***/";
public static Retrofit retrofit = null;
public static Retrofit getRetrofitInstance() {
if (retrofit ==null){
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
和ApiService代码
@FormUrlEncoded
@POST("login.php")
Call<User>LogUser(
@Field("email") String email,
@Field("password") String password
);
没有显示错误,因为我有5个移动设备并且3个移动设备可以进行身份验证,而另外两个则无法识别。