public void click(View view) {
Intent intent = new Intent();
// 指定拍照的意图。
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(),System.currentTimeMillis()+".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); // 指定保存文件的路径
startActivityForResult(intent, 100);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==100){
iv.setImageURI(Uri.fromFile(file));
}
super.onActivityResult(requestCode, resultCode, data);
}
其中MediaStore.ACTION_IMAGE_CAPTURE是照相,还有一个其他的是拍摄视频,这个是goole官方的demo