You can register the ForegroundServiceType
by the [Service]
attribute:
[Service(Exported = false, ForegroundServiceType = global::Android.Content.PM.ForegroundService.TypeDataSync)]public class MainQueryBackgroundService : Service{}
And then remove the
<service android:name="Platforms.Android.MainQueryBackgroundService" android:exported="false" android:foregroundServiceType="dataSync" />
in the AndroidManifest.
Finally, you can start the service by the following code:
if(global::Android.OS.Build.VERSION.SdkInt < global::Android.OS.BuildVersionCodes.Tiramisu){ StartForeground(1, notification);}else{ StartForeground(1, notification, global::Android.Content.PM.ForegroundService.TypeDataSync);}
Fore more information, you can refer to the official document about Foreground service types are required.