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

How can we customize the notification. #221

Closed
iZakirSheikh opened this issue Dec 11, 2022 · 1 comment
Closed

How can we customize the notification. #221

iZakirSheikh opened this issue Dec 11, 2022 · 1 comment
Assignees
Labels

Comments

@iZakirSheikh
Copy link

I tried to override the function onUpdateNotification.
But the service gets disconnected as soon as the user leaves the activity.

Is there a way so that we can provide the custom notification manger.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Dec 12, 2022

If the service never has been started, the service is terminated by the system when the last client that was bound to the service unbinds. This is standard behaviour for services on Android. So you would have to start the service first as a foreground service and then manage the foreground state accordingly.

Recommended approach

If you only want to customize the notification, then you only need to provide a custom MediaNotificationProvider. You can do that by either a) customizing the DefaultMediaNotificationProvider, or b) subclassing a DefaultMediaNotificationProvider or c) writing your own implementation of MediaNotificationProvider.

Then use MediaSessionService.setMediaNotificationProvider(provider) in your onCreate method of the service to set the customized notification provider.

Please also see issue #216 that gives a bit more details about how you can do this approach.

Handling service state yourself

While this gives you full control it adds quite some fun to your media app development that I personally would try to avoid as an app. While it is possible to override onUpdateNotification, this is a complex topic and we are not able to provide support for this. It requires a bit of knowledge of services, foreground and bound services and their restrictions on various API levels.

See also this search query in this issue tracker that gives a taste of the journey.

DAC Guides:
Services overview
Foreground services
Bound services overview

API related behaviour changes:
Android 8 behavior changes
Android 12 behavior changes

API doc:
Service
ServiceInfo

I'm closing this issue because the DefaultNotificationProvider approach is covered in #216 and we can not give you support for overriding onUpdateNotification beyond the doc pointers above.

@androidx androidx locked and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants