检查用户是否已授予NotificationListener访问我的应用程序的权限 [英] Check if user has granted NotificationListener access to my app
本文介绍了检查用户是否已授予NotificationListener访问我的应用程序的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码打开通知侦听器设置":
I'm using this code to open Notification Listener Settings:
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
我想检查用户是否已授权我的应用程序. 我已经尝试检查NotificationListenerService是否正在运行,但是它似乎已被系统暂停并重新启动(即使我返回了START_STICKY).
I would like to check if the user has granted authorization to my app. I already tried to check if my NotificationListenerService is running, but it seems that it gets halted and restarted by the system (even if I return START_STICKY).
推荐答案
我错了,检查服务是否正在运行:
I was wrong, checking if service is running works:
private boolean isNLServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (NLService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
这篇关于检查用户是否已授予NotificationListener访问我的应用程序的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文