Android Question TargetSDK 34 issue with notification

Scantech

Well-Known Member
Licensed User
Longtime User
Copying updated assets files (122)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
BillingResult IsSuccess = False, ResponseCode = BILLING_UNAVAILABLE
Debug string: Billing service unavailable on device.
false
BillingResult IsSuccess = False, ResponseCode = BILLING_UNAVAILABLE
Debug string: Billing service unavailable on device.
onAuthStateChanged: com.google.firebase.auth.internal.zzv@64ab966
** Activity (main) Create (first time) **
java.lang.NoSuchFieldException: No field mFastScroll in class Landroid/widget/AbsListView; (declaration of 'android.widget.AbsListView' appears in /system/framework/framework.jar!classes4.dex)
FILE NOT AVAILABLE ...VALIDATEPAIDUSER
** Activity (main) Resume **
*** Service (tripgpsdistance) Create ***
** Service (tripgpsdistance) Start **
*** Service (comserial) Create ***
** Service (comserial) Start **
*** Service (communicationroutine) Create ***
Partial wakeLock already held.
** Service (communicationroutine) Start **
android.permission.ACCESS_FINE_LOCATION true
android.permission.ACCESS_COARSE_LOCATION true
android.permission.BLUETOOTH_SCAN true
android.permission.BLUETOOTH_CONNECT true
android.permission.NEARBY_WIFI_DEVICES true
android.permission.POST_NOTIFICATIONS true
** Service (tripgpsdistance) Start **
** Service (comserial) Start **
** Service (communicationroutine) Start **
StartTimerandNotification Event
Error occurred on line: 1412 (TripGPSDistance)
android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{39e1489 10245:scantech.cardiagnosticpro/u0a191} targetSDK=34
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
at android.os.Parcel.readParcelableInternal(Parcel.java:4870)
at android.os.Parcel.readParcelable(Parcel.java:4852)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3052)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
at android.app.Service.startForeground(Service.java:775)
at anywheresoftware.b4a.objects.ServiceHelper.StartForeground(ServiceHelper.java:85)
at scantech.cardiagnosticpro.tripgpsdistance._starttimerandnotification(tripgpsdistance.java:2091)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

B4X:
Service.StartForeground(1, CreateNotification("..."))

B4X:
Sub CreateNotification (Body As String) As Notification
    'Used in Start Event for setting up StartForeground
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Sound = False
    notification.Vibrate = False
    notification.Light = False
    notification.Icon = "icon"
    notification.SetInfo("Status", Body, Starter.WhatFormName)  
    Return notification
End Sub

Return nofitication is line 1412

TargetSDKMax 33 is ok not 34
 
Last edited:
Solution
B4X:
SetServiceAttribute(TripGPSDistance, android:foregroundServiceType, "location")
AddPermission(android.permission.FOREGROUND_SERVICE_LOCATION)

This fixed it in manifest

Scantech

Well-Known Member
Licensed User
Longtime User
Permission required? Maybe this will help but i have no clue how to fix this.

ServiceCompat.startForeground(0, notification, FOREGROUND_SERVICE_TYPE_LOCATION)
Constant to pass to startForeground()
 
Last edited:
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Permission required? Maybe this will help but i have no clue how to fix this.

ServiceCompat.startForeground(0, notification, FOREGROUND_SERVICE_TYPE_LOCATION)
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User

B4X:
<manifest ...>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
    <application ...>
      <service
          android:name=".MyMediaPlaybackService"
          android:foregroundServiceType="mediaPlayback"
          android:exported="false">
      </service>
    </application>
</manifest>

If an app that targets Android 14 doesn't define types for a given service in the manifest, then the system will raise MissingForegroundServiceTypeException upon calling startForeground() for that service.

Edit: Probably related to location?
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
SetServiceAttribute(TripGPSDistance, android:foregroundServiceType, "location")
AddPermission(android.permission.FOREGROUND_SERVICE_LOCATION)

This fixed it in manifest
 
Upvote 0
Solution
Top