Lyokone / flutterlocation

A Flutter plugin to easily handle realtime location in iOS and Android. Provides settings for optimizing performance or battery.
MIT License
1.08k stars 785 forks source link

MethodChannelLocation.enableBackgroundMode #961

Open dharambudh1 opened 2 weeks ago

dharambudh1 commented 2 weeks ago

MethodChannelLocation.enableBackgroundMode

Stack trace: PlatformException(error, Service.startForeground() not allowed due to mAllowStartForeground false: service com.ahinsaaggregator.vendor/com.lyokone.location.FlutterLocationService, null, android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.ahinsaaggregator.vendor/com.lyokone.location.FlutterLocationService at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54) at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50) at android.os.Parcel.readParcelableInternal(Parcel.java:4882) at android.os.Parcel.readParcelable(Parcel.java:4864) at android.os.Parcel.createExceptionOrNull(Parcel.java:3064) at android.os.Parcel.createException(Parcel.java:3053) at android.os.Parcel.readException(Parcel.java:3036) at android.os.Parcel.readException(Parcel.java:2978) at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7234) at android.app.Service.startForeground(Service.java:775) at com.lyokone.location.FlutterLocationService.d(SourceFile:1) at bb.h.a(SourceFile:1) at bb.h.onMethodCall(SourceFile:1) at xb.j$a.a(SourceFile:1) at ob.c.l(SourceFile:1) at ob.c.m(SourceFile:1) at ob.c.i(SourceFile:1) at ob.b.run(SourceFile:1) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) )

Screenshot from 2024-06-22 10-53-38

Flutter version: Flutter (Channel stable, 3.19.3, on Ubuntu 24.04 LTS 6.8.0-35-generic, locale en_US.UTF-8) Plugin version: location: ^6.0.2 Device information: Samsung Galaxy A23 running Android 14

edwinmacalopu commented 6 days ago

You are missing this permission uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"

dharambudh1 commented 5 days ago

Thank you for the reply! I am currently utilizing <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />, while <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> is not documented anywhere. Let's test it out.

edwinmacalopu commented 5 days ago

android.permission.FOREGROUND_SERVICE_LOCATION

Since Android 14, the permission is required https://developer.android.com/develop/background-work/services/foreground-services?hl=es-419#fgs-prerequisites