Setting camera audio restrictions

221 Views Asked by At

I am trying to implement a barcode scanning app and would like to vibrate the phone, as soon as a barcode has been detected through the camera. I am using CameraX with ML Kit. Trough trial and error I have determined, that the vibration is muted as long as either the CameraX Preview or the ImageAnalyzer are bound to the camera provider.

I have found that this could be very likely the Camera Audio Restriction mode, that suppresses vibration or sounds coming from ringtones, alarms or notifications. Through the Camera2 API this mode can be set through setCameraAudioRestriction. Is it somehow possible to set this mode through the CameraX API?

1

There are 1 best solutions below

0
On BEST ANSWER

CameraX does not use that API (and it's a recent new API, added in Android 11). You can check yourself if you want by searching through its repository

Unfortunately, it's more likely that the device manufacturer of your test device is disabling vibration when the camera is open - you might be able to test this with other camera apps and receiving a chat message or something else that normally triggers a notification.

The reason for the disable would likely be that optical image stabilization and vibration don't get along well. But it's still not great to unilaterally do that.

You can see if other devices are similarly affected, but currently CameraX isn't likely the cause.