I've figured out how to get android to run some Java code on the systemwide BOOT_COMPLETED
event. It's not clear to me what I need to do next to start my app in some form. As a novice android developer, I'm not even sure exactly if I can call into the JS side of the app at this point - is it even initialized?
Right now, on my personal device, the app crashes around this code:
Context context = getApplicationContext();
Intent myIntent = new Intent(context, BootUpHandlerService.class);
context.startService(myIntent);
...on the startService
call, I get a BackgroundServiceStartNotAllowedException
.
I presume this means I need to call startForegroundService
instead, but the android docs say that may not be possible with Android 12.
The docs also seem to suggest I can start a WorkManager task. Given all the code I've written to use WorkManager tasks actually does so from javascript through a 3rd party library, I have no clue how to even do that from Java. All of my code to prepare for the work I want to do in the background and initialize the tasks themselves is in the frontend, running in an expo/react-native context. Sure, poor practice, but I can refactor once I understand what I need to refactor it into.
While I appreciate what they are doing here as an end user who hates the numerous services running in the background on my phone, it does seem confusing for a novice android developer.
What should I do instead? How do I run JS without the frontend to schedule WorkManager tasks? The docs seem to say I can't even do that, not even with a "notification trampoline".