Android - music player in the notification screen

2019-07-02 21:02发布

问题:

How would one go about creating a simple music player in the top pull-down screen (i.e. where the notifications go)? The default music player on my phone currently does this, and just has a simple previous track, play/pause, and next track buttons.

I already know how to use pending intent to launch a separate activity from up there, I'm just not sure how to get more content up there that the user can interact with.

Hope I described that well enough

Thanks.

回答1:

Android doesn't support notifications with active elements (such as buttons) until 3.0. If your device is older than 3.0, the manufacturer has customized it for their apps but this is not supported for third party apps.

As of 3.0, you can simply put buttons in the notification RemoteViews that send intents back to your app to have you perform actions.



回答2:

This involves creating a status bar notification with a custom expanded view. Look at http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView for guidance on how to do this.