BootReceiver.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.bgy.autosale;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.Build;
  6. import android.util.Log;
  7. import com.hboxs.base_library.util.LogUtil;
  8. import com.hboxs.base_library.util.LogUtils;
  9. /**
  10. * create by cjx on 2023/11/19
  11. */
  12. public class BootReceiver extends BroadcastReceiver {
  13. @Override
  14. public void onReceive(Context context, Intent intent) {
  15. Log.d("BootReceiver", "收到:" + intent.getAction());
  16. LogUtils.logWrite("安卓屏上电");
  17. if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {//开机启动广播
  18. Intent start = new Intent();
  19. start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  20. start.setAction("com.bgy.action.main");
  21. start.setPackage(context.getPackageName());
  22. context.startActivity(start);
  23. Intent severIntent = new Intent(App.app, RemoteSupportService.class);
  24. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  25. context.startForegroundService(severIntent);
  26. } else {
  27. context.startService(severIntent);
  28. }
  29. }
  30. }
  31. }