How to open the application automatically after boot? (Android 10)

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


2 Replies

RS Ruba Shanmugam Syncfusion Team October 4, 2022 09:34 AM UTC

Hi Oskay,


Currently, we are validating the reported query and we will let you know the details on October 11, 2022. We appreciate your patience until then.


Regards,

Ruba Shnam



MI Mohammed Ismail Sameer Mohamed Saleem Syncfusion Team October 13, 2022 11:05 AM UTC

Hi Oskay,


We checked this behavior to find a solution. It seems Google has introduced some limitations in the broadcast receiver and applied some restrictions on background services. So, we are not able to achieve this behavior.


Please find the below reference link for more details,

https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers

https://developer.android.com/guide/components/activities/background-starts


We request you to post queries related to Syncfusion components/products to get better solutions and suggest you to refer other general forums for these kinds of common queries.



Regards,

Sameer M


Loader.
Up arrow icon