通过Android 11中的Android App后台访问Microphone,在Logcat中会抛出以下异常:
W/ActivityManager: Foreground service started from background can not have location/camera/microphone access同样的代码在Android10及更低版本中也能完美运行。如何修复它?
发布于 2020-10-12 00:27:11
在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);但即便如此,安卓11也不允许应用程序在后台访问麦克风/摄像头。唯一的解决方案是使用辅助功能。在此之后,它将像以前一样工作。但是Google Play应用程序在使用辅助功能之前必须仔细检查策略,如果使用它是安全的,否则你的应用程序可能会因为使用变通方法而被暂停。
https://stackoverflow.com/questions/64306400
复制相似问题