Closed CClaudiu26 closed 2 months ago
Same issue on Xiaomi here as well as Motorola Moto G84
This is a valid issue. Microphone doesn't work when the phone is locked or the app is in the background. It only works when the app is back in the foreground.
This is related to https://developer.android.com/develop/background-work/services/fg-service-types#microphone from sdk 34.
The main issue seems to be that we are starting the VoiceConnectionService foreground service too early here https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209
I think we should start this foreground service when the call is answered, somewhere here https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java#L464
What happens right now is that this foregroundservice https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209 fails silently if you dont have microphone permission already.
The only way around this atm is to request for the microphone permission upfront before you receive a call. This can be bad for UX.
Please if you have some time you can share how this call https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209 can be delayed/recalled onanswer of the call. @manuquentin
I can then make a PR for this
@nero2009 for some of my users the issue seems to be happening even if they have allowed microphone permissions before the call has been initialized so this might not be the only issue
This may be related to the additional permissions required for Android 14 to add foreground service type: https://developer.android.com/about/versions/14/changes/fgs-types-required.
In short, add following permissions to the AndroidManifest.xml
:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
I've made doc change in this PR: https://github.com/react-native-webrtc/react-native-callkeep/pull/806.
I've merged #806. Thanks @wkwiatek for your work on investigating it.
Not sure if this fixes this issue.
Last time I checked https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L348 still fails cos we need the RECORD_AUDIO runtime permission before we can start that foreground service.
Ideally we should start that foreground service when the call is answer not when the call is received. I could be wrong tho.
You can always start you own foreground service using this https://rn-foreground.vercel.app/ or implement yours and expose via native modules
Bug report
[ ] I've checked the example to reproduce the issue.
Reproduced on:
Description
Is anyone having issue with microphone when the screen is locked or the app is in background? I didn't have any problem with android 13, but after the update to 14 I had this issue.
Versions
Logs