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
140 stars 105 forks source link

Android 14 Permission related crash #212

Closed bhavinb98 closed 3 months ago

bhavinb98 commented 5 months ago

I already have the following permissions declared in my manifest but it still throws an error and crashes. Flutter version - 3.19.3 Plugin Version - 6.1.3

<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<service
    android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
    android:foregroundServiceType="mediaPlayback|camera|microphone|mediaProjection"
    android:stopWithTask="true"/>
java.lang.RuntimeException: Unable to create service com.pravera.flutter_foreground_task.service.ForegroundService: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{73ae391 7353:com.sprintstudio.conversations/u0a190} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media]
GaelleJoubert commented 5 months ago

I am using other permissions, but they need to be not only in the manifest, but explicitly asked to the user (with permission_handler pluggin for exemple). Maybe this is the same for you ? Have you tried to ask them to the user ?

bhavinb98 commented 5 months ago

Yes, I am asking the relevant permissions.

I'm also asking for these permissions which are required for foreground task to work

await FlutterForegroundTask.requestIgnoreBatteryOptimization();
await FlutterForegroundTask.requestNotificationPermission();
ishabodiwala commented 4 months ago

Hey @bhavinb98, i am getting the same issue. Are you able to solve the issue ?

bhavinb98 commented 3 months ago

@ishabodiwala no, not yet

UnluckyY1 commented 3 months ago

this may help

bhavinb98 commented 3 months ago

Have tried it already. It's not working.

bhavinb98 commented 3 months ago

@ishabodiwala Possible solution for your issue