Android Studio Android 10 Vivo funtouch OS在刷卡时杀死了我的前台服务?

rmbxnbpk  于 2023-01-31  发布在  Android
关注(0)|答案(1)|浏览(189)

我正在开发的应用程序中,我开始计数很长一段时间,为此,我有startforeground服务的服务是在所有设备中工作正常,除了像Android 10 vivo funtouch os的少数设备。其中,当你刷卡通知它杀死foregorund服务,所以要解决这个问题,只有少数设备的行为,谢谢

class MyCountdownService : Service(){

@RequiresApi(Build.VERSION_CODES.O)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

  

    Log.i("Boot","intent is ${intent?.action}")

    showNotification()

    wakeLock =
        (getSystemService(Context.POWER_SERVICE) as PowerManager).run {
            newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EndlessService::lock").apply {
                acquire()
            }
        }

    println("intent ${intent }")
    isServiceStarted =true

  if(intent!=null) {
      val action = intent?.action

      when(action){

          MyCountdownService.ADD_SERVICE ->{
              val countdown = intent.getParcelableExtra<CountDown>(Add_kEY)
              schedule(countdown !!)

          }

          else ->{

              Log.i("Boot","Service boot ")
              serviceScope.launch(Dispatchers.IO) {
                  smsScheduler.reSchedule()
              }

          }

      }


  }else{



      serviceScope.launch(Dispatchers.IO) {
          smsScheduler.reSchedule()
      }

  }

    return START_STICKY } }

//清单文件

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
   
    <service android:name=".service.MyService"

        />
cwdobuhd

cwdobuhd1#

请按照步骤在Android 10 Vivo funtouch OS设备中启用前台服务。
设置〈电池〈后台功耗管理〈您的应用〈选择不限制后台功耗。More details

相关问题