Browse Source
移除RECEIVE_BOOT_COMPLETED权限和BootReceiver,避免应用在系统启动时自动运行 同时移除WorkManager的RescheduleReceiver以优化后台行为newdev_shunjiawei
5 changed files with 8 additions and 48 deletions
Binary file not shown.
@ -1,33 +0,0 @@ |
|||
package com.yunqiinnovation.ble_service |
|||
|
|||
import android.content.* |
|||
import android.os.Build |
|||
import android.util.Log |
|||
/** |
|||
* 系统启动接收器 |
|||
* 当系统重启完成后,自动启动BLE前台服务 |
|||
* 注意:需要用户在设置中授予应用自启动权限才能生效 |
|||
*/ |
|||
class BootReceiver : BroadcastReceiver() { |
|||
private val TAG = "BootReceiver" |
|||
override fun onReceive(ctx: Context, i: Intent) { |
|||
val serviceClass = try { |
|||
Log.d(TAG, "BleMediaService不存在") |
|||
Class.forName("com.yunqiinnovation.agent_service.BleMediaService") |
|||
} catch (e: ClassNotFoundException) { |
|||
Log.d(TAG, "BleMediaService不存在") |
|||
return |
|||
} |
|||
if (i.action == Intent.ACTION_BOOT_COMPLETED) { |
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) |
|||
{ |
|||
Log.d(TAG, "BleMediaService") |
|||
ctx.startForegroundService(Intent(ctx, serviceClass)) |
|||
} |
|||
else{ |
|||
Log.d(TAG, "BleMediaService") |
|||
ctx.startService(Intent(ctx, serviceClass)) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue