when i try to register by my app i didn't get any respnse

B.Thakur

I am trying to save my data to server. can any one help me?

when i am trying to save data through browser it is working fine but when i try it through this code doesn'n give any response??

public class Register extends AppCompatActivity implements View.OnClickListener {

private static final String TAG = "dRegister";
EditText etName, etEmail, etMobile, etPassword, /*etRePassword*/
        etCity;
Button register;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    etName = (EditText) findViewById(R.id.name);
    etEmail = (EditText) findViewById(R.id.email);
    etMobile = (EditText) findViewById(R.id.mobile);
    etCity = (EditText) findViewById(R.id.etCity);
    etPassword = (EditText) findViewById(R.id.password);
    //etRePassword = (EditText) findViewById(R.id.rePassword);
    register = (Button) findViewById(R.id.bRegister);
    register.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    final String name = etName.getText().toString();
    final String email = etEmail.getText().toString();
    final String password = etPassword.getText().toString();
    final String city = etCity.getText().toString();
    final String phoneno = etMobile.getText().toString();

    StringRequest registerRequest = new StringRequest(Request.Method.POST,RegisterRequest.REGISTER_REQUEST_URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d(TAG, response + " Response");
            if(response.equals("SUCCESS")){
                startActivity(new Intent(Register.this,MainActivity.class));
            }
            else{
                Toast.makeText(Register.this, "You have not Registered!", Toast.LENGTH_SHORT).show();
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "Error " + error.toString());
            if(error.networkResponse == null){
                if(error.getClass().equals(TimeoutError.class));
                Toast.makeText(Register.this, "oops Time out error!", Toast.LENGTH_SHORT).show();
            }
        }
    }){
        @Override
        public Map<String, String> getHeaders()throws AuthFailureError{
            Map<String, String> headers = new HashMap<>();
            headers.put("name",name);
            headers.put("email",email);
            headers.put("password",password);
            headers.put("city",city);
            headers.put("phoneno",phoneno);
            return headers;
        }
    };
    registerRequest.setRetryPolicy(new DefaultRetryPolicy(1000 * 15,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    /*Response.Listener<String> responseListener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, response + "");
            try {
                JSONObject jsonResponse = new JSONObject(response);
                boolean success = jsonResponse.getBoolean("success");
                if (success) {
                    Intent intent = new Intent(Register.this, MainActivity.class);
                    startActivity(intent);
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
                    builder.setMessage("Registration failed").setNegativeButton("Retry", null)
                            .create().show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    };
    RegisterRequest registerRequest = new RegisterRequest(name, email, city, phoneno, password, responseListener){
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            //super.getHeaders();
            Map<String,String> headers = new HashMap<>();
            String credential = "[email protected]:123";
            String auth = "Basic "+ Base64.encodeToString(credential.getBytes(),Base64.NO_WRAP);
            //headers.put("Content-Type");
            headers.put("Authorization",auth);
            //
            return headers;
        }
    };*/
            RequestQueue queue = Volley.newRequestQueue(Register.this);
            registerRequest.setShouldCache(false);
            queue.add(registerRequest);
}
}

Here Is my server code....

@RequestMapping(value = "/savemobileUser", method = RequestMethod.POST)
public @ResponseBody String saveUser(@RequestBody MobileUserModel mobileUser) {

    MobileUserModel user = new MobileUserModel();
    user.setActivationKey(mobileUser.getActivationKey());
    user.setCity(mobileUser.getCity());
    user.setEmail(mobileUser.getEmail());

    user.setImeino(mobileUser.getImeino());

    user.setName(mobileUser.getName());

    user.setPassword(mobileUser.getPassword());

    user.setPhoneno(mobileUser.getPhoneno());

    userrepository.save(user);

    System.out.println("Saved");

    // return "User has been saved Successfully";
    return "SUCCESS";

}
techroid

Put following inside your onClick method:

switch (v.getId()) {
        case R.id.bRegister:


            // add your registration process code here



            break;
}   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related