Jul 4, 2024 Replies: 1 by following @Erel Update on this Post https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#post-993226 targeting Sdkversion = 34, if you have a foregroundservice that do media play back in the background you will need to add this to your manifest in order to migrate to targetsdk 34 B4X: Copy ' sdk 34 SetServiceAttribute(Your_Service_Name, android:foregroundServiceType, "mediaPlayback") AddPermission(android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK) Starting service Code B4X: Copy Private Sub StartForegroundService(Service As Object) Dim p As Phone If p.SdkVersion <= 26 Then StartService(Service) Return End If Dim ctxt As JavaObject ctxt.InitializeContext Dim intent As JavaObject intent.InitializeNewInstance("android.content.Intent", Array(ctxt, Service)) ctxt.RunMethod("startForegroundService", Array(intent)) End Sub here is a list of foreground service types. Foreground service types | Background work | Android Developers This document outlines the specific foreground service types required for apps targeting Android 14 (API level 34) and higher, detailing their manifest declarations, associated permissions, runtime prerequisites, and intended use cases. developer.android.com in short B4X: Copy [camera=64, connectedDevice=16, dataSync=1, location=8, mediaPlayback=2, mediaProjection=32, microphone=128, phoneCall=4] this code may not be useful on the next B4a Release, have a great day. Click to expand...
by following @Erel Update on this Post https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#post-993226 targeting Sdkversion = 34, if you have a foregroundservice that do media play back in the background you will need to add this to your manifest in order to migrate to targetsdk 34 B4X: Copy ' sdk 34 SetServiceAttribute(Your_Service_Name, android:foregroundServiceType, "mediaPlayback") AddPermission(android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK) Starting service Code B4X: Copy Private Sub StartForegroundService(Service As Object) Dim p As Phone If p.SdkVersion <= 26 Then StartService(Service) Return End If Dim ctxt As JavaObject ctxt.InitializeContext Dim intent As JavaObject intent.InitializeNewInstance("android.content.Intent", Array(ctxt, Service)) ctxt.RunMethod("startForegroundService", Array(intent)) End Sub here is a list of foreground service types. Foreground service types | Background work | Android Developers This document outlines the specific foreground service types required for apps targeting Android 14 (API level 34) and higher, detailing their manifest declarations, associated permissions, runtime prerequisites, and intended use cases. developer.android.com in short B4X: Copy [camera=64, connectedDevice=16, dataSync=1, location=8, mediaPlayback=2, mediaProjection=32, microphone=128, phoneCall=4] this code may not be useful on the next B4a Release, have a great day.
Erel B4X founder Staff member Licensed User Longtime User Jul 4, 2024 #2 Note that the StartForegroundService code is not required unless you are trying to start the service from the background (from a Receiver most probably). In other cases you can simply call the StartService keyword.
Note that the StartForegroundService code is not required unless you are trying to start the service from the background (from a Receiver most probably). In other cases you can simply call the StartService keyword.