android调用系统摄像头拍照图片和视频

woolnil 2012-02-28

public void onClick(View v) {   //启动系统相机   
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
startActivityForResult(intent, CASE_CAMERA);  }

拍摄完成后的回调函数(在同一个activity中):

protected void onActivityResult(int requestCode, int resultCode, Intent data)方法即可
 
如:
 
final int TAKE_PICTURE = 1;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode ==  CASE_CAMERA) {
    if (resultCode == RESULT_OK) {
      Bitmap bm = (Bitmap) data.getExtras().get("data");
      imgPhoto.setImageBitmap(bm);
          }
  }
}

  

相关推荐