Advertisement
Guest User

login

a guest
Apr 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. public void buttonLogin(View v) {
  2.  
  3.         String url = "https://luiscm.000webhostapp.com/login.php";
  4.         JSONObject jsonBody = new JSONObject();
  5.  
  6.         StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>(){
  7.             @Override
  8.             public void onResponse(String response){
  9.                 try{
  10.                     JSONObject jsonoutput = new JSONObject(response);
  11.                     Toast.makeText(MainActivity.this, jsonoutput.getString(Utils.param_status).toString() + jsonoutput.getString(Utils.param_id_user).toString() + jsonoutput.getString(Utils.param_id).toString() + jsonoutput.getString(Utils.param_nome).toString(), Toast.LENGTH_SHORT).show();
  12.                     Intent i = new Intent(MainActivity.this, MenuActivity.class);
  13.                     startActivity(i);
  14.                 } catch(JSONException ex){
  15.  
  16.                 }
  17.             }
  18.         }, new Response.ErrorListener(){
  19.             @Override
  20.             public void onErrorResponse(VolleyError error){
  21.                 Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
  22.             }
  23.         }){
  24.             @Override
  25.             protected Map<String,String> getParams(){
  26.                 username = (EditText) findViewById(R.id.edituser);
  27.                 password = (EditText) findViewById(R.id.edit2);
  28.  
  29.                 String username1 = username.getText().toString();
  30.                 String password1 = password.getText().toString();
  31.  
  32.                 Map<String,String> params = new HashMap<>();
  33.                 params.put("username",username1);
  34.                 params.put("password",password1);
  35.                 return params;
  36.             }
  37.  
  38.             @Override
  39.             public Map<String, String> getHeaders() throws AuthFailureError{
  40.                 Map<String,String> params = new HashMap<>();
  41.                 params.put("Content-type","application/x-www-form-urlencoded");
  42.                 return params;
  43.             }
  44.         };
  45.  
  46.         MySingleton.getInstance(this).addToRequestQueue(stringRequest);
  47.  
  48.  
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement