gpt4 book ai didi

android - 我可以在代码中显式启动 NotificationListenerService 而不是由操作系统为我启动它吗?

转载 作者:行者123 更新时间:2023-11-29 14:17:04 25 4
gpt4 key购买 nike

我有一个派生自 NotificationListenerService 的类,它会在应用程序启动时自动为我创建和启动。但是,我想稍后从 Activity 中懒惰地启动该服务,而不是在应用程序启动时自动启动它。是否有可能做到这一点? list 是:

    <service android:name=".MyNotificationListener"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>

请注意,在使用 NotificationListenerService 之前,用户必须通过设置授予应用通知访问权限。但是,如果从 list 中删除了 Intent 过滤器,则应用程序不会出现在设置中,因此用户无法授予权限,因此未经许可服务无法启动。似乎操作系统需要那个 Intent 过滤器才能在设置中显示应用程序。

更新:BIND_NOTIFICATION_LISTENER_SERVICE 的文档说:

Must be required by an NotificationListenerService, to ensure that only the system can bind to it.

所以我想这意味着只有操作系统可以启动 NotificationListenerService,而其他任何人都不能。

最佳答案

是的。为服务创建一个 Intent,然后调用 startService。

关于android - 我可以在代码中显式启动 NotificationListenerService 而不是由操作系统为我启动它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29397644/

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