-2
Hi I asked a question and could not help me, I have a webservice who’s making a get that when entered the user name it will allow access to the application and thus will pass the user to the next screen.
That is the code:
public class LoginActivity extends AppCompatActivity {
public static final String PREFS_USER = "Preferencia";
EditText user;
Button salvar;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
user = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.senha);
salvar = (Button) findViewById(R.id.salvar);
salvar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences settings = getSharedPreferences(PREFS_USER, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("PrefUser", user.getText().toString());
editor.putString("PrefPass", password.getText().toString());
//Confirma a gravação dos dados
editor.commit();
loadJson(user.getText().toString());
}
});
SharedPreferences settings = getSharedPreferences(PREFS_USER, 0);
user.setText(settings.getString("PrefUser", ""));
password.setText(settings.getString("PrefPass", ""));
}
public void loadJson(String usuario){
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://"+getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getString("PrefHost", "") +":8080/FazendaWebservice/webresources/fazenda/")
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
AcessoClient client = retrofit.create(AcessoClient.class);
Call<Acesso> call = client.reposForUsuario(usuario);
call.enqueue(new Callback<Acesso>() {
@Override
public void onResponse(Call<Acesso> call, Response<Acesso> response) {
}
@Override
public void onFailure(Call<Acesso> call, Throwable t) {
Toast.makeText(LoginActivity.this, " Erro ao estabelecer conexão"+ "\n"+" Verifique o host inserido"+"\n"+"Por favor tente novamente mais tarde!", Toast.LENGTH_SHORT).show();
}
});
}
Class Acesso
:
public class Acesso {
private String nomeusuario;
private String senhausuario;
private String listaprodutos;
private String vendasonline;
public String getNomeusuario() {
return nomeusuario;
}
public void setNomeusuario(String nomeusuario) {
this.nomeusuario = nomeusuario;
}
public String getSenhausuario() {
return senhausuario;
}
public void setSenhausuario(String senhausuario) {
this.senhausuario = senhausuario;
}
public String getListaprodutos() {
return listaprodutos;
}
public void setListaprodutos(String listaprodutos) {
this.listaprodutos = listaprodutos;
}
public String getVendasonline() {
return vendasonline;
}
public void setVendasonline(String vendasonline) {
this.vendasonline = vendasonline;
}
}
Class AcessoClient
:
public interface AcessoClient {
@GET("Acesso/get/{usuario}")
Call <Acesso> reposForUsuario(
@Path("usuario") String usuario
);
}
JSON returned from Webservice
{"nomeusuario":"admin","senhausuario":"yMJsiuiTcpC","listaprodutos":"S","vendasonline":"S"}
I don’t know what to put inside the onResponse so he ends up doing the validation, someone helps me?
Possible duplicate of Validate access with android retrofit
– Daniel Gentil
Dude is not duplicate of anything, they didn’t solve my problem I’m trying, they did this duplicate scheme there, but the other code had nothing to do with my
– Renato Crispim
it will not be by asking several times the same question that will solve :), for that there is the edit, in case someone does not understand your explanation you can improve it, Asking the same questions over and over can even be interpreted as spam and lead to a possible ban or limitation on your account. You asked the same question (changed the words), and copied the same code result yes is duplicated
– Daniel Gentil
Got it, all right, you know how to help me?
– Renato Crispim
Understand @Renatocrim that a duplicate question is a question that has relevance or that addresses the same theme as yours. Hardly the duplicate of the question will have the same code as your question, but the answers of them can guide you in solving the problem.
– Grupo CDS Informática
Yes I know, and I researched and tested the other code I changed it and it didn’t lead me to anything... But I’ve solved thank you
– Renato Crispim