gpt4 book ai didi

android - 如何从 NotificationListenerService 停止前台服务

转载 作者:行者123 更新时间:2023-11-29 02:33:43 24 4
gpt4 key购买 nike

我在我的 android 应用程序中从 Intentservice 启动前台服务,服务开始通知。这就是我开始服务的方式:

Intent intent = new Intent(this, NavigationforegroundService.class);
startService(intent);

我正在 NotificationListenerService 中收听特定应用程序的通知,当该通知被删除时,我正在停止前台服务,但前台服务仍在运行。这就是我停止前台服务的方式:

stopForeground(false);
stopService(new Intent(RemoteViewNotificationReaderService.this, NavigationforegroundService.class));

我找不到任何关于为什么服务没有停止的线索,因为文档还建议使用 stopService() 或 stopSelf() 方法。谁能告诉我我做错了什么,或者从其他服务停止服务的正确方法是什么。

谢谢。

最佳答案

请在下面编写停止前台服务的代码。

从您的服务调用 stopForeground(true) 然后是 stopSelf()

停止前台服务。

关于android - 如何从 NotificationListenerService 停止前台服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48205165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com