Microphone recording in background not working on Android 12

rickmt

New member
Hello,
I'm experiencing an issue with one of my macros I use to record microphone audio in the background. Every time I turn the screen off, the recording is stopped.

I tried to look for a solution, and, as it turns out, apps cannot access the camera/microphone in the background by default ever since Android 11.
When I try to modify MacroDroid's microphone permissions, I'm only given a choice to allow its usage while 'using the app'.

Would there be some way to resolve this issue? I'm using a Samsung Galaxy S22 with Android 12.
 

FrameXX

Well-known member
Hello,
I'm experiencing an issue with one of my macros I use to record microphone audio in the background. Every time I turn the screen off, the recording is stopped.

I tried to look for a solution, and, as it turns out, apps cannot access the camera/microphone in the background by default ever since Android 11.
When I try to modify MacroDroid's microphone permissions, I'm only given a choice to allow its usage while 'using the app'.

Would there be some way to resolve this issue? I'm using a Samsung Galaxy S22 with Android 12.

Since MacroDroid is running a foreground service with persistent notification, it is percieved as in foreground by permission manager. So it's possibke this is some kind of restriction from your manufacturer or...? I really don't think it's caused by Android permission policy.
 

dsnz

Well-known member
my mistake, I'm old fashioned 😂
yes, there are foreground services now

but still in the document it says

When your app starts a foreground service while the app is running in the background, the foreground service has the following limitations:

The foreground service cannot access the microphone or camera.


(note that MD and it's services all start in background at boot)
however since the OP's macros can access the microphone when screen is on
then the access is done by some other way and not a foreground service

but truly the development with Android is very complex
and I may be wrong again 😂
only @MacroDroidDev can explain what is happening and think of workarounds
 

rickmt

New member
Thanks for the replies.
I believe the issue could be fixed if the MacroDroid app would have the START_ACTIVITIES_FROM_BACKGROUND permission, as stated here: https://developer.android.com/guide/components/foreground-services#while-in-use-restrictions

Though I'm not really an expert, so I might be wrong.

By the way, I forgot to mention that it always takes a few seconds for the recording to stop once the screen is turned off, and, for some weird reason, in one instance, the recording didn't stop at all.
 

MacroDroidDev

Administrator
Staff member
That's strange because I don't see the same issue on my devices with Android 12.

I will add the foreground service type to request microphone which currently appears to be missing and hopefully that will solve the issue for you in the next update.
 

rickmt

New member
That's strange because I don't see the same issue on my devices with Android 12.

I will add the foreground service type to request microphone which currently appears to be missing and hopefully that will solve the issue for you in the next update.
Hi,
Sorry for the late reply.
It seems that the issue is still present on my phone (the microphone permission choices remain the same, and the recording still gets cut off); it might be possible that it's a problem specific for my phone model (assuming you've included the missing permission in an update), in which case I'm sorry for bothering you.

Thank you in advance.
 

MacroDroidDev

Administrator
Staff member
I have added the relevant permission (which shouldn't even be required for Android 12). I'm afraid I don't see the issue on any of my Android 12 devices including a Samsung S10+ which is the closest device I have to yours.
 

rickmt

New member
It seems like the actual issue was something different, and everything works the way it should now.
Turns out my phone has a feature called 'put unused apps to sleep', which was stopping the recording. I thought this feature wouldn't affect MacroDroid (since it's set up as a system app and it wasn't even on the list of apps recently put to sleep). I disabled it, and it finally works fine.

Thanks for your helpfulness!
 

LuisVangog

New member
This thread is about a year old, but the issue you described regarding microphone recording on Android 12 remains relevant. As of my last knowledge update in January 2022, Android's restrictions on background microphone access were in place due to security considerations, especially starting from Android 11.
I hope you can find a solution to your microphone recording problem, even though the thread is a bit older.
 
Last edited by a moderator:
Top