简体   繁体   中英

How to check camera Id (primary or secondary) which camera is open currently in android when user capture an image?

How to check camera type(primary or secondary) when user clicks an image in android?

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        fileUri = Utility.getOutputMediaFileUri(MEDIA_TYPE_IMAGE, mContext);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        startActivityForResult(intent, REQUEST_CAMERA);

You can't check in this context. That intent is supposed only to return a capture. If you attempt to open another camera with Camera.open() your app will crash.

You should implement a custom camera capture activity, in which you can have full control and also camera object. Then check on camera object which one is used.

How to check camera type(primary or secondary) when user clicks an image in android?

You don't. The image is the image. Whether it was taken by the front-facing camera, the rear-facing camera, a USB-connected camera, an IP camera, or is just some piece of clip art, is up to the camera app that happened to take this picture. There are hundreds of different camera apps, both pre-installed and user-installed.

If the returned image has EXIF header , you can parse it to find the camera characteristics. Most likely, you will be able to determine whether it was taken with the front-facing or rear-facing camera.

Often, the rear-facing camera has higher resolution, and you can simply check if the photo resolution fits this. Note that on most built-in camera apps, MediaStore.ACTION_IMAGE_CAPTURE intent does not allow the user to choose camera resolution, so the photo will be of default size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM