android 调用系统相机

 private void init(View view) {
  btnCam1 = (ImageButton) view.findViewById(R.id.verify_img1);
  btnCam2 = (ImageButton) view.findViewById(R.id.verify_img2);

//拍照
  btnCam1.setOnClickListener(new OnClickListener() {   
   @Override
   public void onClick(View arg0) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //intent.putExtra("btnCamId", "1");
    intent.putExtra("camerasensortype", 2);//调用前置摄像头
    intent.putExtra("autofocus", true);// 是否自动聚焦
    intent.putExtra("fullScreen", true);// 是否全屏
    intent.putExtra("showActionIcons", false);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "DHCCFaceDetect.jpg")));
    startActivityForResult(intent, 1);
   }
  });

//冲图库中获取图片
  btnCam1.setOnLongClickListener(new OnLongClickListener() {   
   @Override
   public boolean onLongClick(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK, null);
    intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
    //intent.putExtra("btnCamId", "1");
    startActivityForResult(intent, 2);
    return true;
   }
  });



@Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
  
  super.onActivityResult(requestCode, resultCode, data);  
  switch (requestCode) {
  case 1:
   if (resultCode == Activity.RESULT_OK) {
    File temp = new File(Environment.getExternalStorageDirectory() + "/DHCCFaceDetect.jpg");
    startPhotoZoom(Uri.fromFile(temp), 4);
   }
   break;
  case 2:
   if (data != null) {
    startPhotoZoom(data.getData(), 4);
   }
   break;
  }
 }
 

你可能感兴趣的:(android 调用系统相机)