Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 444

Answer by Liyun Zhang - MSFT for Maui Xamarin service problem with android 12,14

$
0
0

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.


Viewing all articles
Browse latest Browse all 444

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>