android: Fix launching on device boot

This commit is contained in:
Colin Edwards 2023-12-22 12:30:45 -06:00
parent 793a12d58d
commit 3d8e285e2b
2 changed files with 12 additions and 1 deletions

View File

@ -44,6 +44,9 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service

View File

@ -8,11 +8,19 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.util.Set;
public class Receiver extends BroadcastReceiver {
private static final Set<String> BOOT_ACTIONS = Set.of(
"android.intent.action.BOOT_COMPLETED",
"android.intent.action.QUICKBOOT_POWERON"
);
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Receiver", "onReceive: " + intent);
if (intent.getAction() == "android.intent.action.BOOT_COMPLETED") {
if (BOOT_ACTIONS.contains(intent.getAction())) {
if (Settings.Preferences.getBoolean(context,
Settings.Preferences.KEY_RUN_ON_BOOT,
false)) {