private void saveUserInfo(){
dialog.setMessage("Loading");
dialog.show();
String name = txtName.getText().toString().trim();
String lastName = txtLastname.getText().toString().trim();
StringRequest request = new StringRequest(Request.Method.POST, Constant.SAVE_USER_INFO, response->{
try {
JSONObject object = new JSONObject(response);
if(object.getBoolean("success")){
SharedPreferences.Editor editor = userPref.edit();
editor.putString("photo", object.getString("photo"));
editor.apply();
startActivity(new Intent(UserInfoActivity.this, HomeActivity.class));
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
dialog.dismiss();
}, error->{
error.printStackTrace();
dialog.dismiss();
}) {
//add token to headers
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
String token = userPref.getString("token", "");
HashMap<String, String> map = new HashMap<>();
map.put("Authorization", "Bearer" +token);
return map;
}
//add Params
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> map = new HashMap<>();
map.put("name", "name");
map.put("lastname", "lastname");
map.put("photo", bitmapToString(bitmap));
return map;
}
};
RequestQueue queue = Volley.newRequestQueue(UserInfoActivity.this);
queue.add(request);
}