如何解决Android 11/R - 使用从后台启动的前台服务警报接收器开始录制音频/视频
在使用 Android R/targetSdkVersion 30 时,有没有办法在前台服务从后台启动时开始录制音频或视频,例如警报接收器?
也许我做错了什么或不明白如何安排闹钟?
他们不希望应用程序在没有用户交互的情况下开始录制。当用户按下按钮或通知时,录制运行正常。他们说我可以使用 PendindIntent - 所以我用它来设置一个稍后启动服务的警报,不是吗?但是当警报接收器启动服务并尝试录制时 - 它被此消息阻止:
"从后台启动的前台服务不能有
位置/相机/麦克风访问“
他们声明:
When a foreground service starts in one of the following situations,the service is exempt from the restrictions on while-in-use access to location,camera,and microphone:
The service is started by a system component.
The service is started by interacting with app widgets.
The service is started by interacting with a notification.
The service is started as a **PendingIntent** that is sent from a different,visible app.
The service is started by an app that is a device policy controller that is running in device owner mode.
The service is started by an app which provides the **VoiceInteractionService**.
The service is started by an app that has the START_ACTIVITIES_FROM_BACKGROUND privileged permission.
我不完全理解的选项,也许可以解开这个谜:
- 立即运行服务,直到警报响起。它可以工作,但会耗尽电池电量。
- “VoiceInteractionService”作为服务的启动还是将服务转换为 VoiceInteractionService?
- 将服务更改为“AccessibilityService” - 我读到 google play 不喜欢它。
- 使用 JobScheduler 而不是 alarmreceiver 或其他 Worker 类型?
我试过这样的直接报警:
Intent intent = new Intent(mContext,MainService.class);
intent.setAction(Constants.ACTION.ALARM_START_AND_RECORD);
PendingIntent pendingIntent = PendingIntent.getService(mContext,intent,0);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pendingIntent);
或者使用报警接收器:
Intent intent = new Intent(mContext,AlarmReceiver.class);
intent.setAction(Constants.ACTION.ALARM_START_AND_RECORD);
pendingIntent = PendingIntent.getBroadcast(this.getActivity(),REQUEST_SET_ALARM,PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,pendingIntent);
定位 sdk 29 (targetSdkVersion 29) 没有帮助,它之前有帮助,但看起来他们已经改变了上一个 android 11 :-(
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。