I am able to display toast message in BootReceiver. I cannot start the application. I managed to autostart on a device with android api 25, but the target device is Android api 29. Any ideas on this?
How can I start the application automatically when Android boot complate?
BootReceiver.cs
using Android.App;
using Android.Content;
using Android.Widget;
namespace MaRadio.Platforms.Android
{
[BroadcastReceiver(Label = "BootReceiver", DirectBootAware = true, Enabled = true, Exported = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.HighPriority)]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, " Service Running ", ToastLength.Long)?.Show();
var launch_intent = Platform.CurrentActivity?.PackageManager?.GetLaunchIntentForPackage(Platform.CurrentActivity.PackageName);
if (launch_intent != null)
{
launch_intent.AddFlags(ActivityFlags.ReorderToFront);
launch_intent.AddFlags(ActivityFlags.NewTask);
launch_intent.AddFlags(ActivityFlags.ResetTaskIfNeeded);
Platform.CurrentActivity?.StartActivity(launch_intent);
}
}
}
}
AndroidManifest.xml
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.SYSTEM_ALERT_WINDOW
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET