【发布时间】:2019-05-08 14:43:48
【问题描述】:
我需要你的帮助来解决这个问题:
Context.startForegroundService() did not then call Service.startForeground()
我正在使用 BroadcastReceiver 来启动通知服务:
@Override
public void onReceive(Context context, Intent intent) {
WakeLock.acquire(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ContextCompat.startForegroundService(context, new Intent(context, StartNotificationService.class).putExtras(intent));
} else {
context.startService(new Intent(context, StartNotificationService.class).putExtras(intent));
}
}
请问你有什么想法吗?我该如何解决这个问题? 谢谢你
【问题讨论】:
-
您必须在前台服务中调用
startForeground。这是添加的,我相信奥利奥(不太确定)。你有一个时间窗口来做这件事。如果您没有在这段时间内调用它,Android 会抛出该异常。
标签: android android-notifications