|
|
@@ -0,0 +1,38 @@
|
|
|
+package com.grkj.iscs.receivers
|
|
|
+
|
|
|
+import android.app.AlarmManager
|
|
|
+import android.app.PendingIntent
|
|
|
+import android.content.BroadcastReceiver
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import com.grkj.iscs.util.log.LogUtil
|
|
|
+import com.grkj.iscs.view.activity.LoginActivity
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 开机启动接收器
|
|
|
+ * */
|
|
|
+class BootReceiver : BroadcastReceiver() {
|
|
|
+ override fun onReceive(context: Context, intent: Intent?) {
|
|
|
+ if (intent!!.action.equals("android.intent.action.BOOT_COMPLETED")) {
|
|
|
+ LogUtil.d("接收到启动通知,开始启动应用")
|
|
|
+ //开机2秒后启动程序
|
|
|
+ val startAppIntent = Intent(
|
|
|
+ context, LoginActivity::class.java
|
|
|
+ ).apply {
|
|
|
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
+ }
|
|
|
+ //启动应用,得使用PendingIntent
|
|
|
+ val startAppPendingIntent =
|
|
|
+ PendingIntent.getActivity(
|
|
|
+ context, 0, startAppIntent,
|
|
|
+ PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
|
+ );
|
|
|
+ val mAlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
|
|
+ mAlarmManager.set(
|
|
|
+ AlarmManager.RTC, System.currentTimeMillis() + 2000,
|
|
|
+ startAppPendingIntent
|
|
|
+ ) // 2秒钟后重启应用
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|