Hi Everyone,
I've problem in calling the Foreground Service from the Broadcast Receiver when the app was killed by user. It is working fine when the app is open or recent apps.
Actually, my requirement is to track the location for every X minutes even the app is killed / closed.
So, I created a Broadcast Receiver for Location service. And It is not working in Android 7 when the app got killed.
So, I created a Repeating Alarm and calling foreground service from alarm Receiver. It is working fine when the app is open. But not when app got killed.
I make the Alarm Receiver as
<receiver android:process=":remote" android:name="ScheduledAlarmHandler"></receiver>
to run process even app got killed
Code to Alarm Receiver
public async override void OnReceive(Context context, Intent intent)
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
if (ActivityCompat.CheckSelfPermission(context, Android.Manifest.Permission.AccessFineLocation) == Android.Content.PM.Permission.Granted)
{
var msg = new StartServiceMessage();
Xamarin.Forms.MessagingCenter.Send<StartServiceMessage>(msg, "ServiceStarted");
}
}
}
Can anyone help me with right approach.
Thanks in Advance.