最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

media - ForegroundServiceStartNotAllowedException and Android 15 - Stack Overflow

programmeradmin0浏览0评论

I have an app that starts a service in the MediaBrowserService's onLoadChildren. We can argue about how starting a service there is fundamentally wrong but i have a legacy app that depends on that and for the sake of the discussion let's live with that decision.

The problem comes with MediaResumption: for Media Apps the OS will call onGetRoot and then onLoadChildren after a reboot to populate the media notification in the system tray and allow users to resume where they left off.

In Android 15 starting a media service after BOOT_RECEIVED is not allowed anymore, so my app is now always throwing an exception after a reboot:

android.app.ForegroundServiceStartNotAllowedException: FGS type mediaPlayback not allowed to start from BOOT_COMPLETED!

What I dont understand here is that according to the docs:

If a BOOT_COMPLETED receiver tries to launch any of those types of foreground services, the system throws ForegroundServiceStartNotAllowedException.

However my app is NOT a BOOT_COMPLETED receiver, i dont have a broadcast receiver observing this event, but this comes as a result of Media resumption. So I'm wondering, what needs to happen after a reboot so I can actually start that service? Is it time-bound? Cause for the sake of testing I caught the exception and just keep retrying to start the service, and i am still getting the same exception after 5+ minutes.

发布评论

评论列表(0)

  1. 暂无评论