如何在Android Lollipop中删除前台通知? [英] How do i remove a foreground notification in Android Lollipop?

查看:155
本文介绍了如何在Android Lollipop中删除前台通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望停止/关闭针对媒体播放器的服务的前台通知,这与Google对Google Music的实现非常相似.

I'm looking to stop/dismiss a foreground notification for a service for a mediaplayer, much similar to Google's implementation for Google Music.

例如在Google音乐中,如果您正在播放音乐,则通知不会被清除.但是,如果您暂停音乐,则可以.

For instance in Google Music, if you are playing music then the the notification cannot be swiped away. However if you pause the music it can.

这与在Android 4.4上实现的方式完全不同,在Android 4.4中,通知仅在您离开应用程序时才开始,而在您返回应用程序时便会自行删除.考虑到服务具有通知的要求,我既看不到如何实现这一点.

This is completely different to how it is implemented on Android 4.4, where the notification starts only when you leave the app and removes itself when you go back into the app. I can't see how to implement this either considering the requirements for a service to have a notification.

任何帮助将不胜感激.

Any help would be much appreciated.

推荐答案

如何在Android Lollipop中删除前台通知?

How do i remove a foreground notification in Android Lollipop?

您可以通过从称为startForeground()Service中调用stopForeground()来删除自己的前景Notification.

You can remove your own foreground Notification by calling stopForeground() from your Service, that called startForeground().

例如在Google音乐中,如果您正在播放音乐,则通知不会被清除.但是,如果您暂停音乐,则可以将其轻扫一下.

For instance in Google Music, if you are playing music then the the notification cannot be swiped away. However if you pause the music, you can swipe it away.

大概是他们根据音乐是否在播放来更新NotificationsetOngoing()值.

Presumably, they are updating the setOngoing() value for the Notification based upon whether or not the music is playing.

这篇关于如何在Android Lollipop中删除前台通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆