I'm trying to create a custom camera preview like the one used by WhatsApp. To illustrate the problem, I'm adding an image below:
I'm using the following code to open the camera activity:
imgCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, 2);
}
});
And trying the below to show up the preview:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
Intent startPreview = new Intent(this.getContext(), PreviewActivity.class);
startPreview.putExtra("path", path);
startActivity(startPreview);
}
super.onActivityResult(requestCode, resultCode, data);
}
However, it is not showing up my preview custom activity. It is showing the common one.
Could someone help me?
Thank you
It won't show your activity, because the intent you specify is ACTION_IMAGE_CAPTURE which states:
Standard Intent action that can be sent to have the camera application capture an image and return it.
If you have your custom activity to handle camera capture/preview/etc. you need to call new Intent(Context, YourActivity.class)