gpt4 book ai didi

android - 检查用户是否已授予 NotificationListener 访问我的应用程序的权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:22 26 4
gpt4 key购买 nike

我正在使用此代码打开通知监听器设置:

startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));

我想检查用户是否已授权我的应用程序。我已经尝试检查我的 NotificationListenerService 是否正在运行,但它似乎被系统暂停并重新启动(即使我返回 START_STICKY)。

最佳答案

唯一正确的方法是检查安全设置:

ComponentName cn = new ComponentName(context, YourNotificationListenerService.class);
String flat = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
final boolean enabled = flat != null && flat.contains(cn.flattenToString());

关于android - 检查用户是否已授予 NotificationListener 访问我的应用程序的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20141727/

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