Android判断app是否打开消息通知并跳转设置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_30512027/article/details/80859934

1、判断是否打开

NotificationManagerCompat notification = NotificationManagerCompat.from(this);
boolean isEnabled = notification.areNotificationsEnabled();

2、跳转系统设置

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE) {
    // 进入设置系统应用权限界面
    Intent intent = new Intent(Settings.ACTION_SETTINGS);
    startActivity(intent);
    return;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 运行系统在5.x环境使用
    // 进入设置系统应用权限界面
    Intent intent = new Intent(Settings.ACTION_SETTINGS);
    startActivity(intent);
    return;
}

跳转应用系统设置

public static final String SETTINGS_ACTION =
        "android.settings.APPLICATION_DETAILS_SETTINGS";

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE) {
            Intent intent = new Intent()
                    .setAction(SETTINGS_ACTION)
                    .setData(Uri.fromParts("package",
                            getApplicationContext().getPackageName(), null));
            startActivity(intent);
            return;
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Intent intent = new Intent()
                    .setAction(SETTINGS_ACTION)
                    .setData(Uri.fromParts("package",
                            getApplicationContext().getPackageName(), null));
            startActivity(intent);
            return;
        }


猜你喜欢

转载自blog.csdn.net/weixin_30512027/article/details/80859934