我看到一些应用程序有一个小对话框,要求允许应用程序监听通知。该对话框有 2 个按钮:取消和执行(打开安全设置以允许应用程序监听通知)。该对话框是持久的,所以我猜它有一种方法来检测该应用程序是否被允许。任何人都可以向我指出该 API 吗?谢谢
最佳答案
我知道这是一个老问题,但这是我现在在我的应用程序中使用的:
String notificationListenerString = Settings.Secure.getString(this.getContentResolver(),"enabled_notification_listeners");
//Check notifications access permission
if (notificationListenerString == null || !notificationListenerString.contains(getPackageName()))
{
//The notification access has not acquired yet!
}else{
//Your application has access to the notifications
}
您可以通过打开 Activity 将用户移至通知访问权限
设置:
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
从 Jelly Bean 4.3 到 Marshmallow 6.0 都经过了很好的测试,我在我的应用程序中使用了它。
关于android - 通知监听服务 : detect if application is allowed to listen for notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22289883/