最近做讯飞语音开发,唤醒后打卡语音听写,APP在前台一切正常,但是把应用最小化后持续唤醒功能正常,唤醒后却无法打卡语音听写了,报错20006。使用安卓11机子测试的。我前台服务也开了就是不行。试了无数方法,包括提工单给讯飞客服无果。最后在安卓开发者官网找到答案
Foreground services in Android 11 | Android Developers
Android 11 changes when foreground services can access the device's location, camera, and microphone. This helps protect sensitive user data.
Camera and microphone foreground service types
If your app targets Android 11 or higher and accesses the camera or microphone in a foreground service, you must include the camera
and microphone
foreground service types.
注意这段话,必须在你的AndroidManifest里面的service声明里面加上这句才可以!
<service android:name=".XXXService" android:foregroundServiceType="microphone"/>