主题:android调用系统摄像头拍照图片和视频
如题:
- public void onClick(View v) { //启动系统相机
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- startActivityForResult(intent, CASE_CAMERA);
public void onClick(View v) { //启动系统相机 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CASE_CAMERA); }
public void onClick(View v) { //启动系统视频摄像头
- Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
- startActivityForResult(intent, CASE_VIDEO);
- }
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(intent, CASE_VIDEO); }
拍摄完成后的回调函数(在同一个activity中):
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- try{
- if(resultCode==Activity.RESULT_OK){
- if(requestCode==CASE_CAMERA){
- typeMulti = 0;
- Bundle extras = data.getExtras();
- Bitmap bitmap= (Bitmap) extras.get("data");
- path = IOUtils.saveImg(bitmap); //返回图片保存在本机中的目录
- /*Toast toast=Toast.makeText(this, "相片已保存在:SDcard/DCIM/Camera目录中", Toast.LENGTH_LONG);
- toast.setGravity(Gravity.BOTTOM, 0, 0);
- toast.show();*/
- isUploadPhoto(bitmap);
- }
- if(requestCode==CASE_VIDEO){
- typeMulti = 1;
- path = data.getData().toString();
- /*Toast toast=Toast.makeText(this, "视频已保存在:"+path, Toast.LENGTH_LONG);
- toast.setGravity(Gravity.BOTTOM, 0, 0);
- toast.show();*/
- uploadVideoDialog();
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }