Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 109 forks source link

android:foregroundServiceType="microphone" #291

Closed mening12001 closed 1 day ago

mening12001 commented 3 days ago

There is an issue when setting the type of the service to "microphone" on Android 14. The android.permission.FOREGROUND_SERVICE_MICROPHONE must be acquired.

Please consider solving this issue by including the permission request. Thank you!

Dev-hwang commented 1 day ago

Hello, @mening12001

To start the foreground service on android14, foregroundServiceType and permission are required.

https://developer.android.com/about/versions/14/changes/fgs-types-required#microphone

image

Therefore, you must be declared as follows in the Manifest:

<!-- required -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- foregroundServiceType: microphone -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- Warning: Do not change service name. -->
<service 
    android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
    android:foregroundServiceType="microphone"
    android:exported="false" />

Here is a demo app that uses this permission.

https://github.com/Dev-hwang/flutter_foreground_task_example/tree/main/record_service

mening12001 commented 1 day ago

Hello, Thank you for the response.