Android Question TargetSDK 34 issue with notification

Scantech

Well-Known Member
Licensed User
Longtime User

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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…