Advertisement
Guest User

asas

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