moazelsawaf / dash_bubble

A Flutter plugin that allows you to create a floating bubble on the screen 💙
https://pub.dev/packages/dash_bubble
BSD 3-Clause "New" or "Revised" License
46 stars 14 forks source link

MissingForegroundServiceTypeException when trying to start the bubble on ANDROID 14(works on lower versions) : Unable to start service dev.moaz.dash_bubble.src.BubbleService@e61ab63 with Intent. #19

Open dhiaCodes opened 2 months ago

dhiaCodes commented 2 months ago

Starting the bubble on Android 14 causing the app to exit and throws this exception:


E/AndroidRuntime( 9443): java.lang.RuntimeException: Unable to start service dev.moaz.dash_bubble.src.BubbleService@e61ab63 with Intent { cmp=com.example.naest/dev.moaz.dash_bubble.src.BubbleService (has extras) }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{bf3359e 9443:com.example.naest/u0a190} targetSDK=34
E/AndroidRuntime( 9443):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839)
E/AndroidRuntime( 9443):    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
E/AndroidRuntime( 9443):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
E/AndroidRuntime( 9443):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 9443):    at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime( 9443):    at android.os.Looper.loop(Looper.java:294)
E/AndroidRuntime( 9443):    at android.app.ActivityThread.main(ActivityThread.java:8177)
E/AndroidRuntime( 9443):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9443):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime( 9443):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/AndroidRuntime( 9443): Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{bf3359e 9443:com.example.naest/u0a190} targetSDK=34
E/AndroidRuntime( 9443):    at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
E/AndroidRuntime( 9443):    at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
E/AndroidRuntime( 9443):    at android.os.Parcel.readParcelableInternal(Parcel.java:4870)
E/AndroidRuntime( 9443):    at android.os.Parcel.readParcelable(Parcel.java:4852)
E/AndroidRuntime( 9443):    at android.os.Parcel.createExceptionOrNull(Parcel.java:3052)
E/AndroidRuntime( 9443):    at android.os.Parcel.createException(Parcel.java:3041)
E/AndroidRuntime( 9443):    at android.os.Parcel.readException(Parcel.java:3024)
E/AndroidRuntime( 9443):    at android.os.Parcel.readException(Parcel.java:2966)
E/AndroidRuntime( 9443):    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
E/AndroidRuntime( 9443):    at android.app.Service.startForeground(Service.java:775)
E/AndroidRuntime( 9443):    at com.torrydo.floatingbubbleview.FloatingBubbleService.notify(FloatingBubbleService.kt:225)
E/AndroidRuntime( 9443):    at dev.moaz.dash_bubble.src.BubbleService.showNotification(BubbleService.kt:114)
E/AndroidRuntime( 9443):    at dev.moaz.dash_bubble.src.BubbleService.onStartCommand(BubbleService.kt:25)
E/AndroidRuntime( 9443):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821)
E/AndroidRuntime( 9443):    ... 9 more
I/Process ( 9443): Sending signal. PID: 9443 SIG: 9
Lost connection to device.

Exited.
lehoangbaochung commented 1 month ago

Declare this permission in your AndroidManifest.xml like this:

    <uses-permission
        android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"
        android:foregroundServiceType="dataSync"
        android:minSdkVersion="34" />