Android 读取通知权限

读取方法:

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 读取通知权限)