android camera, video 연동 및 촬영후 저장되는 기본 경로 구하기 예제


		ImageButton ibt_camera = (ImageButton) findViewById(R.id.ibt_camera);	// 카메라 버튼 
		ibt_camera.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();

				if(mPickupFileMode == Const.MediaStoreType.Image){	// 사진
					intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
				}else{	// 동영상
					intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
				}
				
				startActivityForResult(intent, Const.RequestCodes.REQ_CAMERA_SELECT);	
			}
		});

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
			case Const.RequestCodes.REQ_CAMERA_SELECT:	// 카메라 버튼 선택 결과  
				if(resultCode == RESULT_OK){
					if(mPickupFileMode == Const.MediaStoreType.Image){	// 사진
						String mCapturePhotoPath = getRealPathFromURI(data.getData());	// 사진 기본 저장 경로
						if(DEBUG) Toast.makeText(this, "Image saved to:\n" + mCapturePhotoPath, Toast.LENGTH_SHORT).show();
						return;
					}else{	// 동영상
						String mCaptureVideoPath = getRealPathFromURI(data.getData());	// 동영상 기본 저장 경로
						if(DEBUG) Toast.makeText(this, "Video saved to:\n" + mCaptureVideoPath, Toast.LENGTH_SHORT).show();
						return;
					}

				}			    
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	public String getRealPathFromURI(Uri contentUri) {
		// can post image
		String [] proj={MediaStore.Images.Media.DATA};
		Cursor cursor = managedQuery( contentUri,
				proj, // Which columns to return
				null,       // WHERE clause; which rows to return (all rows)
				null,       // WHERE clause selection arguments (none)
				null); // Order-by clause (ascending by name)
		int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
		cursor.moveToFirst();
		return cursor.getString(column_index);
	}




+ Recent posts