package jp.takke.datastats;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import jp.takke.util.MyLog;

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        
        MyLog.i("BootReceiver.onReceive");

        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // 端末起動時の処理
            
            // 自動起動の確認
            final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
            final boolean startOnBoot = pref.getBoolean(C.PREF_KEY_START_ON_BOOT, false);
            
            MyLog.i("start on boot[" + (startOnBoot ? "YES" : "NO") + "]");
            
            if (startOnBoot) {
                // サービス起動
                final Intent serviceIntent = new Intent(context, LayerService.class);
                context.startService(serviceIntent);
            }
        }
        
    }
}

@@ -169,16 +169,41 @@
 rences;%0A
+import android.os.Build;%0A
 import a
@@ -1016,16 +1016,163 @@
 class);%0A
+                if (Build.VERSION.SDK_INT %3E= 26) %7B%0A                    context.startForegroundService(serviceIntent);%0A                %7D else %7B%0A    
         
@@ -1208,32 +1208,50 @@
 serviceIntent);%0A
+                %7D%0A
             %7D%0A  

Fix crash on boot (Android 8.0 or later)