我从github的florent37下载了相机片段项目。 安装后,它会安装,但拍摄快照后不会导航到预览页面。
@OnClick(R.id.record_button)
public void onRecordButtonClicked() {
final CameraFragmentApi cameraFragment = getCameraFragment();
if (cameraFragment != null) {
cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultAdapter() {
@Override
public void onVideoRecorded(String filePath) {
Toast.makeText(getBaseContext(), "onVideoRecorded " + filePath, Toast.LENGTH_SHORT).show();
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
Toast.makeText(getBaseContext(), "onPhotoTaken " + filePath, Toast.LENGTH_SHORT).show();
}
},
"/storage/self/primary",
"photo0");
}
}
上面是处理onclick侦听器的示例代码
然后有更多用于侦听器的代码
if (cameraFragment != null) {
cameraFragment.setResultListener(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(String filePath) {
Intent intent = PreviewActivity.newIntentVideo(CameraFragmentMainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE);
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
Intent intent = PreviewActivity.newIntentPhoto(CameraFragmentMainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE);
}
});