美文网首页
Android 读取通知权限

Android 读取通知权限

作者: yunhen | 来源:发表于2018-10-08 14:18 被阅读409次

读取方法:

public boolean isNotificationListenerEnabled() {
     try {
            String packageName = getApplication().getPackageName();
            String str1 = Settings.Secure.getString(getContentResolver()
                    ,"enabled_notification_listeners");
            if (!TextUtils.isEmpty(str1)) {
                String[] strings = str1.split(":");
                for (String string : strings) {
                    ComponentName localComponentName 
                            = ComponentName.unflattenFromString(string);
                   if ((localComponentName == null) 
                            || (!TextUtils.equals(packageName,localComponentName.getPackageName()))) {
                        LogUtils.instance().d(TAG,localComponentName.getPackageName());
                    } else {
                        return true;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

跳转到设置

Intent notificationSettingIntent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
 startActivityForResult(notificationSettingIntent, REQ_CODE_INIT_NOTIFICATION);

相关文章

网友评论

      本文标题:Android 读取通知权限

      本文链接:https://www.haomeiwen.com/subject/sxxjaftx.html