0

I have put in place the following:

I added <receiver android:name="BootReceiver"></receiver> to application in the manifest XML file.

I added <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> to the manifest also.

I created a new class in the droid project called BootReceiver:

using Android.App;
using Android.Content;
using uarapp.droid;

[BroadcastReceiver(Enabled = true, DirectBootAware = true, Exported = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.HighPriority)]
public class BootReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        Intent i = new Intent(context, typeof(MainActivity));
        i.AddFlags(ActivityFlags.NewTask);
        context.StartActivity(i);
    }
}

The app does not start when the device boots. From Googling it looks like this process has changed for latest version of Android. Anybody know what needs to change? I can't find it online anywhere.

In case it matters the specific device I'm targetting is a RealWear HMT-1.

Salbrox
  • 143
  • 1
  • 15
  • I test your code at Android 6.0, app can auto start, but Android 10 can not auto start, as FreakyAli said that you can show a service notification at specific time. – Cherry Bu - MSFT Aug 17 '21 at 07:59

1 Answers1

0

A lot has changed with Android 10 there are a lot of restrictions on starting something in the background more information here.

The possible solution is in the following answer on SO: https://stackoverflow.com/a/59421118/7462031

Possible Solutions:

1- You can choose just show a service notification, and start pending intent with a click 2- You can use full-screen intents to show your intent immediately as shown in the other answer and suggested by Google. For full-screen intent solution, as described in the official document The system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device. 3- To start the activity automatically in the background, The most possible solution in my view is adding "SYSTEM_ALERT_WINDOW" to the manifest file. And ask for user permission once when the app opened the first time. (The user can give this permission manually - (Settings-Apps-Your App-Advanced- Draw over other apps))

I have also read about some brands restricting the above solutions so you might wanna investigate that too.

Good luck feel free to get back if you have queries.

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Thanks for the suggestions, I'll check them out. This does not need to run in the background. It's a full screen app that will be the only app this device uses. We want to remove as many steps to getting into the app as possible. – Salbrox Aug 18 '21 at 14:09
  • Looking at the list here: https://developer.android.com/guide/components/activities/background-starts the first exception would seem to apply but in practise the app doesn't start. Am I misunderstanding this? – Salbrox Aug 18 '21 at 14:11
  • It does apply in this case – FreakyAli Aug 23 '21 at 05:06
  • I see. So there is some other issue preventing the app from starting I guess... – Salbrox Aug 24 '21 at 12:35
  • My guess is it could be a brand restriction could you confirm the same? – FreakyAli Aug 24 '21 at 12:38