Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the context to shouldStartForegroundService #1887

Closed
johngray1965 opened this issue Nov 14, 2024 · 3 comments
Closed

Pass the context to shouldStartForegroundService #1887

johngray1965 opened this issue Nov 14, 2024 · 3 comments
Assignees

Comments

@johngray1965
Copy link

[REQUIRED] Use case description

In order to implement androidx.media3.session.MediaButtonReceiver.shouldStartForegroundService, I need to inject something. I can either use @androidentrypoint or use @entrypoint. The former doesn't work because the dagger generated code overrides onReceive and androidx.media3.session.MediaButtonReceiver implementation of onReceive is final. The latter doesn't because I don't have context needed to use the @entrypoint.

Proposed solution

Where the androidx.media3.session.MediaButtonReceiver calls shouldStartForegroundService, it has a context. In fact it uses when it calls ContextCompat.startForegroundService, in order to correctly implement shouldStartForegroundService I need same information.

Alternatives considered

Copying the code from androidx.media3.session.MediaButtonReceiver to implement my own (not a great option).

Note, this is with 1.5.0-rc01

@marcbaechinger
Copy link
Contributor

Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

@johngray1965
Copy link
Author

Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

Thank you. That'll be very helpful.

copybara-service bot pushed a commit that referenced this issue Nov 18, 2024
@marcbaechinger
Copy link
Contributor

marcbaechinger commented Nov 18, 2024

The change is available in main and will be included in the next release. Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants