android - Android 11 中的后台麦克风访问引发异常
问题描述
Microphone
通过 Android 应用程序的后台访问Android 11
在 Logcat 中引发以下异常:
W/ActivityManager: Foreground service started from background can not have location/camera/microphone access
相同的代码在 Android 10 及更低版本中完美运行。如何解决?
解决方案
在后台访问位置或摄像头或麦克风的服务Android 11
需要在文件中添加以下内容:AndroidManifest.xml
<manifest>
...
<service ...
android:foregroundServiceType="location|camera|microphone" />
</manifest>
另外,在方法中添加以下内容startForeground
:
Service.startForeground(notification,
FOREGROUND_SERVICE_TYPE_LOCATION | FOREGROUND_SERVICE_TYPE_CAMERA | FOREGROUND_SERVICE_TYPE_MICROPHONE);
但即便如此,Android 11 也不允许应用在后台获取麦克风/摄像头访问权限。唯一的解决方案是使用辅助功能。之后它将像以前一样工作。但是如果可以安全使用,Google Play 应用程序必须在使用辅助功能之前仔细检查政策,否则您可能会冒着应用程序因使用变通方法而被暂停的风险。
推荐阅读
- javascript - 无法在 Next 中传递道具
- r - 即使我在 R 中指定源的路径后也无法获取文件
- android - 带有-prod“启用”的android上的离子慢启动
- java - Android Java:将 else-if 转换为 switch
- python - 使用tensorflwo2.0,应该如何查看tensor的值
- mongodb - 处理字段名称中的空格
- python - 安装了一个 python 库,但是(从 IDLE 运行它)每当我尝试导入它时,它都会返回一个 ModuleNotFoundError
- tensorflow - TensorFlow 在第一个 epoch 中的未知步骤
- javascript - JavaScript 模块中的事件监听器?
- python - ImportError:在 Ubuntu 18.04 上没有名为 meep 的模块