In Android 12 google introduced users can enable and disable camera and microphone access for all apps on the device by pressing a single toggle option. For more information visit here.
As per documentation we can check which device support toggle mode for camera and microphone by using following code
SensorPrivacyManager sensorPrivacyManager = getApplicationContext()
.getSystemService(SensorPrivacyManager.class);
boolean supportsMicrophoneToggle = sensorPrivacyManager
.supportsSensorToggle(Sensors.MICROPHONE);
boolean supportsCameraToggle = sensorPrivacyManager
.supportsSensorToggle(Sensors.CAMERA);
As per documentation The camera and microphone toggles affect all apps on the device:
- When the user turns off camera access, your app receives a blank camera feed.
- When the user turns off microphone access, your app receives silent audio.
My question is Is there any way to observe toggle state of camera and microphone so we can prevent streaming blank camera and silent audio?
If you go through SensorPrivacyManager class in Android Studio you will find there is addSensorPrivacyListener
but we can not implement it as its accessible if we use it as system application.