Java 无法将用户带到通知设置

Java 无法将用户带到通知设置,java,android,xml,Java,Android,Xml,因此,在我的应用程序中,当用户第一次加载时,他们会得到一个进入通知访问菜单的提示。如果他们选择“是”,它会重定向到它,如果他们说“否”,他们只会进入应用程序页面 private AlertDialog buildNotificationServiceAlertDialog() { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setT

因此,在我的应用程序中,当用户第一次加载时,他们会得到一个进入通知访问菜单的提示。如果他们选择“是”,它会重定向到它,如果他们说“否”,他们只会进入应用程序页面

private AlertDialog buildNotificationServiceAlertDialog() {
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("one");
    alertDialogBuilder.setMessage("two");
    alertDialogBuilder.setPositiveButton("yes",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));
                }
            });
    alertDialogBuilder.setNegativeButton("no",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    return (alertDialogBuilder.create());
}
当我点击是,它只是关闭应用程序,当我按下否,它做它应该做的。我已经在其他应用程序上对此进行了测试,我的应用程序确实显示在通知访问菜单中,但我无法从自己的应用程序重定向到它

有人知道它为什么不起作用吗

谢谢。

试着这样做

 private void enableNotification(){
    Intent intent = new Intent();
    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
    if(Build.VERSION.PREVIEW_SDK_INT<=Build.VERSION_CODES.M) {
        intent.putExtra("app_package", getPackageName());
        intent.putExtra("app_uid", getApplicationInfo().uid);
    }else{
    intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
    }
    startActivity(intent);
}

在intent中添加包名以使用它

Intent notifIntent = new Intent();
notifIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

//for Android 5-7
notifIntent.putExtra("app_package", getPackageName());
notifIntent.putExtra("app_uid", getApplicationInfo().uid);

// for Android 8
notifIntent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());

startActivity(notifIntent);

它将在Android 5.0及以上版本中工作。

这导致应用程序在启动时崩溃。请检查logcat。必须是安全异常。权限相关关于版本支持的更多选项,我发现这很有用。检查这个功能,但我想进入这个菜单,我现在只需要将android.settings.APP\u NOTIFICATION\u设置更改为ACTION\u NOTIFICATION\u LISTENER\u设置