所以我不确定在何处/如何实现此方法以使我的服务在前台运行.目前我在另一项活动中通过以下方式开始我的服务:
Intent i = new Intent(context, myService.class);
context.startService(i);
Run Code Online (Sandbox Code Playgroud)
然后在myServices的onCreate()中我尝试startForeground()......?
Notification notification = new Notification();
startForeground(1, notification);
Run Code Online (Sandbox Code Playgroud)
所以是的,我有点失落,不确定如何实现这一点.
Android 8的电池消耗改进对用户来说很好,但是如果我的服务能按预期工作,我有点害怕.
首先:感谢您提出任何建议,但我不能安排我的服务.我想OK Google在后台运行一个类似的关键字监听器.它将基于开源的pocketsphinx-android库.我知道这会消耗很多电池电量,我会告诉用户这个.
我们可以在android 8+上创建一个永久的后台服务吗?我需要在gradle中定位android 8,因为我期待一些旧目标的bug.我也不想使用前台服务来惹恼用户,该服务会在状态栏中永久显示通知.
[ https://developer.android.com/about/versions/oreo/background.html] - 真的没有办法为我的用例(但最好是所有用例)提供永久性后台服务吗?