Android 使用系统摄像头拍相片与拍视频,并显示

public class OpenCamaraActivity extends BaseActivity {

    private static final int IMAGE_REQUEST_CODE = 0;
    private static final int VIDEO_REQUEST_CODE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void openImage(View view) {
        Intent intent = new Intent();
        intent.setAction("android.media.action.IMAGE_CAPTURE");
        intent.addCategory("android.intent.category.DEFAULT");
        Uri value = Uri.fromFile(new File("/sdcard/image.jpg"));
        intent.putExtra(MediaStore.EXTRA_OUTPUT, value);
        startActivityForResult(intent, IMAGE_REQUEST_CODE);
    }

    public void openVideo(View view) {
        Intent intent = new Intent();
        intent.setAction("android.media.action.VIDEO_CAPTURE");
        intent.addCategory("android.intent.category.DEFAULT");
        Uri value = Uri.fromFile(new File("/sdcard/good.3gp"));
        intent.putExtra(MediaStore.EXTRA_OUTPUT, value);
        startActivityForResult(intent, VIDEO_REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            if (requestCode == IMAGE_REQUEST_CODE) {
                //打开图片
                Uri uri = data.getData();
                ImageView imageView = new ImageView(this);
                imageView.setImageURI(uri);
            }else if (requestCode == VIDEO_REQUEST_CODE) {
                //打开视频
                Uri uri = data.getData();
                //VideoView videoView = (VideoView)this.findViewById(R.id.video_view); 
                VideoView videoView = new VideoView(this);
                videoView.setMediaController(new MediaController(this));    
                videoView.setVideoURI(uri);    
                videoView.start();    
                videoView.requestFocus();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

你可能感兴趣的:(android,视频,摄像头)