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