Android BroadcastReceiver on startup - keep running when Activity is in Background

后端 未结 5 581
眼角桃花
眼角桃花 2020-11-22 05:34

I\'m monitoring incoming SMSs.

My app is working perfectly with a BroadcastReceiver. However it is working from an Activity and would like to keep the <

5条回答
  •  广开言路
    2020-11-22 06:06

    Beside @Javanator answer I would like to include a case for Android version of (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) In my case this is working for Android SDK 29 (10)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          context.startForegroundService(new Intent(context,FloatingWindow.class));
    } else {
          context.startService(new Intent(context, FloatingWindow.class));
      }
    

提交回复
热议问题