간단하게 액티비티 설명드리겠습니다 ㅠㅠ..
일단 먼저 사용자 아이디와 패스워드는 입력되어 있는 상태고
아이디는 intent에서 putExtra 이용하여 넘겨줍니다 이후 httppost 전송할때 nameValuePairs에 아이디값, 닉네임값, 패스워드값, 이미지값 을 넘겨줍니다
여기서 이미지값은 버튼 클릭후 이미지를 선택하여 crop된 이미지입니다.
문제는 여기서입니다
현재 database에 들어가질 않습니다.. ㅠ.ㅠ.
db 생성시 이미지가 들어갈 테이블은 blob로 선언하였습니다..
뭐가 문젠지 제대로 되질 않습니다.. ㅠㅠ..
고수분들의 조언 부탁드리겠습니다 ㅠ.ㅠ..
jsp파일은 첨부하겠습니다
package org.member;
i//import구문은 삭제하였습니다.
public class updateMember extends Activity implements OnClickListener {
private ProgressDialog pDialog;
Button updateBtn, reBtn;
EditText etNICK, etPASS;
ImageView userImage;
Button changeImageBtn;
// 선택되서 crop 된 이미지.
Bitmap selectedImage;
byte[] byteArray;
TextView userText;
String userID;
private static final String TEMP_PHOTO_FILE = "temp.jpg"; // 임시 저장파일
private static final int REQ_CODE_PICK_IMAGE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.adminmember);
userImage = (ImageView) findViewById(R.id.userImage);
changeImageBtn = (Button) findViewById(R.id.changeImageBtn);
changeImageBtn.setOnClickListener(this);
updateBtn = (Button) findViewById(R.id.updateBtn);
updateBtn.setOnClickListener(this);
reBtn = (Button) findViewById(R.id.reBtn);
reBtn.setOnClickListener(this);
etNICK = (EditText) findViewById(R.id.etNICK);
etPASS = (EditText) findViewById(R.id.etPASS);
userID = getIntent().getExtras().getString("id");
userText = (TextView) findViewById(R.id.userText);
userText.setText(userID + "님 환영합니다");
}
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
if (isSDCARDMOUNTED()) {
File f = new File(Environment.getExternalStorageDirectory(), // 외장메모리
// 경로
TEMP_PHOTO_FILE);
try {
f.createNewFile(); // 외장메모리에 temp.jpg 파일 생성
} catch (IOException e) {
}
return f;
} else
return null;
}
/** SD카드가 마운트 되어 있는지 확인 */
private boolean isSDCARDMOUNTED() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED))
return true;
return false;
}
/** 다시 액티비티로 복귀하였을때 이미지를 셋팅 */
protected void onActivityResult(int requestCode, int resultCode,
Intent imageData) {
super.onActivityResult(requestCode, resultCode, imageData);
switch (requestCode) {
case REQ_CODE_PICK_IMAGE:
if (resultCode == RESULT_OK) {
if (imageData != null) {
String filePath = Environment.getExternalStorageDirectory()
+ "/temp.jpg";
System.out.println("path" + filePath); // logCat으로 경로확인.
selectedImage = BitmapFactory.decodeFile(filePath);
// temp.jpg파일을 Bitmap으로 디코딩한다.
byteArray = bitmapToByteArray(selectedImage);
ImageView _image = (ImageView) findViewById(R.id.userImageChange);
_image.setImageBitmap(selectedImage);
// temp.jpg파일을 이미지뷰에 씌운다.
}
}
break;
}
}
@Override
public void onClick(View v) {
if (v == changeImageBtn) {
// 유저 이미지 버튼
Intent intent = new Intent(
Intent.ACTION_GET_CONTENT, // 또는 ACTION_PICK
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*"); // 모든 이미지
intent.putExtra("crop", "true"); // Crop기능 활성화
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); // 임시파일 생성
intent.putExtra("outputFormat", // 포맷방식
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(intent, REQ_CODE_PICK_IMAGE);
// REQ_CODE_PICK_IMAGE == requestCode
}else if(v==updateBtn){
updateProcess();
}
else if (v == reBtn) {
// 다시 쓰기 버튼.
etNICK.setText("");
etPASS.setText("");
}
}
// 비트맵 -> ByteArray
public byte[] bitmapToByteArray(Bitmap $bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
$bitmap.compress(CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
// ByteArray -> 비트맵.
public Bitmap byteArrayToBitmap(byte[] $byteArray) {
Bitmap bitmap = BitmapFactory.decodeByteArray($byteArray, 0,
$byteArray.length);
return bitmap;
}
public String parsingData(InputStream input) {
String result = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new InputStreamReader(input));
while (parser.next() != XmlPullParser.END_DOCUMENT) {
String name = parser.getName();
if (name != null && name.equals("result"))
result = parser.nextText();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public void ContentViewCall() {
Intent intent = new Intent(this, contentView.class);
intent.putExtra("id", etNICK.getText().toString());
startActivity(intent);
finish();
}
private final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pDialog.dismiss();
String result = msg.getData().getString("RESULT");
if (result.equals("success")) {
Toast.makeText(updateMember.this, "성공적으로 회원정보를 수정 하였습니다.",
Toast.LENGTH_LONG).show();
ContentViewCall();
} else {
Toast.makeText(updateMember.this, "회원수정 실패", Toast.LENGTH_LONG)
.show();
}
}
};
public void updateProcess() {
final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse(HttpResponse response)
throws ClientProtocolException, IOException {
String result = null;
HttpEntity entity = response.getEntity();
result = parsingData(entity.getContent());
Message message = handler.obtainMessage();
Bundle bundle = new Bundle();
if (result.equals("success")) {
bundle.putString("RESULT", "success");
Log.v("regedit", "regedit ok !" + result);
} else {
bundle.putString("RESULT", "failed");
Log.v("regedit", "regedit no !" + result);
}
message.setData(bundle);
handler.sendMessage(message);
return result;
}
};
// 로그인이 처리되고 있다는 다이얼로그를 화면에 표시한다.
pDialog = ProgressDialog.show(this, "", "회원정보수정 처리중");
// 서버에 HTTP 처리 요청은 새로운 스레드를 생성하여 비동기식으로 처리하는것이 효율적이다.
new Thread() {
@Override
public void run() {
String url = "http://192.168.0.3:8080/jws/mixare/member/update.jsp";
HttpClient http = new DefaultHttpClient();
try {
// 서버에 전달할 파라메터 세팅
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", userID));
Log.v("id", userID);
if (etNICK.getText().toString().equals("")) {
nameValuePairs.add(new BasicNameValuePair("nick", ""));
Log.v("passwd", etNICK.getText().toString());
} else {
nameValuePairs.add(new BasicNameValuePair("nick",
etNICK.getText().toString()));
Log.v("passwd", etNICK.getText().toString());
}
if (etPASS.getText().toString().equals("")) {
nameValuePairs.add(new BasicNameValuePair("nick", ""));
Log.v("passwd", etPASS.getText().toString());
} else {
nameValuePairs.add(new BasicNameValuePair("nick",
etPASS.getText().toString()));
Log.v("passwd", etPASS.getText().toString());
}
nameValuePairs.add(new BasicNameValuePair("img",
new String(byteArray)));
Log.v("image ?", new String(byteArray));
// 응답시간이 5초가 넘으면 timeout 처리하려면 아래 코드의 커맨트를 풀고 실행한다.
HttpParams params = http.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
// HTTP를 통해 서버에 요청을 전달한다.
// 요청에 대한결과는 responseHandler의 handleResponse()메서드가 호출되어
// 처리한다.
// 서버에 전달되는 파라메터값을 인코딩하기위해 UrlEncodedFormEntity() 메서드를 사용한다.
HttpPost httpPost = new HttpPost(url);
UrlEncodedFormEntity entityRequest = new UrlEncodedFormEntity(
nameValuePairs, "UTF-8");
httpPost.setEntity(entityRequest);
http.execute(httpPost, responseHandler);
Log.v("to jsp", "to jsp is success");
} catch (Exception e) {
e.printStackTrace();
}
}
}.start(); // 스레드를 실행시킨다.
}
}