Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I notified when camera is used or opened by any other application

I want to get notified whenever any other application opened or accessed camera. I already know that I can check Camera.open() and its exception. but for that I have to check every time using service but it drain battery so I want whenever opened camera just notified me and get its package name. I already read these.

How to find whether the camera is in use?

How to check if camera is opened by any application

like image 980
Upendra Shah Avatar asked Nov 04 '25 20:11

Upendra Shah


1 Answers

You can do it using callbacks provided by the API of Camera2.

In your CameraManagerobject you can attach a CameraManager.AvailabilityCallback which will notice you when the camera object is being used or not.

About AvailabilityCallback:

A callback for camera devices becoming available or unavailable to open.

Cameras become available when they are no longer in use, or when a new removable camera is connected. They become unavailable when some application or service starts using a camera, or when a removable camera is disconnected.

You can research more information about it in the official documentation

like image 139
Francisco Durdin Garcia Avatar answered Nov 07 '25 09:11

Francisco Durdin Garcia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!