【问题标题】:Authentication problem on some mobile device某些移动设备上的身份验证问题
【发布时间】:2020-09-18 10:06:36
【问题描述】:

我有一个安卓登录系统,问题是有的手机可以识别,有的不能,但是没有报错。

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();
            }
        });
    }

【问题讨论】:

  • 您能否分享更多代码,例如您的 ApiClient 类和确切的错误(如果您遇到了),以便我们更容易理解
  • 尝试将此“else if (response.body().getResponse().equals("failed"))”更改为 else 以从服务器获取所有不正确的响应“到你的烤面包机。然后你应该看看服务器是否响应了一些意外的东西。
  • 您是否尝试在对话框中执行此方法??
  • 试试这行代码 if (response.body().getResponse().equalsIgnoreCase("ok")
  • 好的,谢谢。没有错误,但它可以在其他设备上运行,但其他设备还没有

标签: java android authentication retrofit2


【解决方案1】:

这是我的 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 部手机可以认证,其他两部无法识别。

【讨论】:

    猜你喜欢
    • 2019-11-18
    • 2018-04-15
    • 1970-01-01
    • 2019-09-18
    • 2011-10-27
    • 1970-01-01
    • 2023-03-15
    • 2016-12-23
    • 1970-01-01
    相关资源
    最近更新 更多