Volley를 사용하여 이미지 및 기타 세부 정보로 프로필을 업데이트하려고합니다.이미지를 파일로 변환하여 volley 및 json URL로 보내기
이미지 파일을 변환하고 url 매개 변수로 보내야합니다.
프로필을 업데이트하기 위해 다른 모든 세부 정보도 구문 분석해야합니다.
프로필 이미지를 업데이트하려면 어떻게해야합니까?
url = "http://192.168.1.30:1021/mobileapi/profile_update.html?&user_id="+user+"&firstname="+First.getText().toString()+
"&lastname="+last.getText().toString()+"&secondaryemail="+sEmail.getText().toString()+
"&phonemobile="+mob.getText().toString()+"&aboutus="+work.getText().toString()+"&phonework="+phone.getText().toString()+
"&skypeid="+skypeid.getText().toString()+"&gender="+gender+"&smtp_password="+mpass.getText().toString()+"&image="+fos;
url=url.trim().replaceAll("\\s+","");
System.out.println("url" + url);
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading...");
pDialog.show();
pDialog.dismiss();
queue = Volley.newRequestQueue(getActivity());
request = new JsonArrayRequest(Request.Method.POST, url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
System.out.println("updaa" + response.toString());
JSONObject update = response.getJSONObject(0);
int httpcode = Integer.parseInt(update.getString("status"));
if (httpcode == 200) {
String mess = update.getString("message");
Toast.makeText(getActivity(), mess, Toast.LENGTH_LONG).show();
int userid = Integer.parseInt(update.getString("user_id"));
String fname = update.getString("firstname");
String lname = update.getString("lastname");
String mail = update.getString("email");
String smail=update.getString("secondary_email");
/* String ph= String.valueOf(Integer.parseInt(update.getString("phone_work")));
String phone= String.valueOf(Integer.parseInt(update.getString("phone_mobile")));*/
String skype_id = update.getString("skype_id");
String user_title = update.getString("user_title");
String imgUrl = update.getString("image");
editor.putString("name", fname);
editor.putString("userid", String.valueOf(userid));
editor.putString("lname",lname);
editor.putString("mail",mail);
editor.putString("skype",skype_id);
editor.putString("image",imgUrl);
// editor.putString("phone", String.valueOf(ph));
editor.putString("work",user_title);
editor.putString("smail",smail);
// editor.putString("phone", String.valueOf(phone));
editor.commit();
} else {
JSONObject typ = response.getJSONObject(0);
String message = typ.getString("message");
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("result" + error.getLocalizedMessage()+"__"+error.getMessage());
Log.e("Volley", "Error");
}
}){
};
queue.add(request);
}
}
});
return view;
}
private void opengallery() {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == PICK_IMAGE_REQUEST && intent != null && intent.getData() != null) {
Uri uri = intent.getData();
try {
/*Uri selectedImageURI = data.getData();
imageFile = new File(getRealPathFromURI(selectedImageURI));*/
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);
Log.d("TAG", String.valueOf(bitmap));
Bpro.setImageBitmap(bitmap);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(uri + ".png");
file = new File(extStorageDirectory, uri + ".png");
Log.e("file exist", "" + file + ",Bitmap= " + uri);
fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fos);
/* fos = new FileOutputStream(f);
fos.write(bitmapdata);*/
} catch (IOException e) {
e.printStackTrace();
}
}
}
JSON 응답
[{
"smtp_password":"abdul",
"status":"200",
"user_type":"2",
"skype_id":"skype",
"emp_id":"N0418",
"phone_work":"9864545454",
"image":"http:\/\/192.168.1.30:1021\/uploads\/Nandha\/profile_image\/180_200\/45571.png",
"lastname":"Rahman",
"firstname":"Abdul",
"user_title":"android",
"message":"Profile has been updated successfully",
"email":"[email protected]",
"gender":"1",
"user_id":"45571",
"secondary_email":"[email protected]",
"phone_mobile":"9892545454"
}]
무엇이 문제입니까? JSON 응답도 표시하십시오. – earthw0rmjim
urlhttp : //192.168.1.30 : 1021/mobileapi/profile_update.html &user_id=45571&firstname=Abdul&lastname=Rahman&[email protected]&phonemobile=9892545454&aboutus=android&phonework=9864545454&skypeid=skype&gender=1&smtp_password=abdul&image=null 난 널 (null)로 이미지를 가지고있다 갤러리에서 이미지를 선택하더라도 –
프로필 이미지를 업데이트해야합니다. 이미지를 파일 –