问题描述
Android 8的电池消耗改进对用户来说不错,但我有点担心我的服务能否按预期工作.
Android 8's battery consumption improvements are nice to the user but I am a bit afraid if my service will work as expected.
首先:谢谢您的任何建议,但我不能只安排我的服务.我想制作一个一直在后台运行的类似OK Google
的关键字侦听器.它将基于开源的Pocketsphinx-android库.我知道这会消耗很多电池电量,因此我会通知用户.
First of all: Thank you for any suggestions but I cannot just schedule my service. I want to make a OK Google
-like keyword listener running in the background all the time. It will be based on the open source pocketsphinx-android library. I know that this will consume much battery power and I will inform the user about this.
我们可以在android 8+上创建永久后台服务吗?我需要在gradle中定位android 8,因为我期望使用较旧的目标会出现一些错误.我也不想让前台服务永久性地在状态栏中显示通知的用户烦恼.
Can we create a permanent background service on android 8+ ? I need to target android 8 in gradle because I was expecting some bugs with older targets. I also don't want to annoy a user with a foreground service which permanently shows a notification in the status bar.
[ https://developer.android.com/about/versions /oreo/background.html] -真的没有办法为我的用例(但最好是所有用例)提供永久的后台服务吗?
[https://developer.android.com/about/versions/oreo/background.html] - Is there really no way of making permanent background services for my use-case (but preferably for all use-cases) possible?
推荐答案
不幸的是,在Android 8.0及更高版本上,无法使用后台服务并且不显示前台通知.
Unfortunately, it's not possible to use a background service and don't show a foreground notification on Android 8.0 and higher.
可能唯一可行的方法是将应用程序坚持使用Google API,例如语音操作API .
The only one way that it might work is if you stick your app to Google APIs such as Voice Actions API.
据我所知,目前尚无很好的解决方法,而像WhatsApp之类的大多数应用仍将Android API 24作为目标.
As far as I know there is no a good work around and most apps like WhatsApp are still targetting Android API 24.
这篇关于Android Oreo上的永久服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!