0

So in my app at the moment when the user first loads it up they get a prompt to go to the Notification access menu. If they select yes it redirects to it, if they say no they go just go onto the apps page.

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());
}

When I click "yes" it just closes the app and when I press "no" it does what it should. I've tested this on with other apps and my app does appear in the Notification access menu but I can't redirect to it from my own app.

Any one have any ideas why it's not working?

Thanks.

2 Answers2

1

Add package name in intent to work it.

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);

It will work in Android 5.0 and above.

Aj 27
  • 2,316
  • 21
  • 29
0

Try to do it this way.

 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);
}
ADM
  • 20,406
  • 11
  • 52
  • 83
  • This caused the app to crash when I start it up – Christopher Mckenzie Jul 25 '17 at 12:58
  • Check the logcat . Must be a Security exception . Permission related – ADM Jul 25 '17 at 13:23
  • For more options for version support i have found this [answer](https://stackoverflow.com/questions/32366649/any-way-to-link-to-the-android-notification-settings-for-my-app) useful . check this out – ADM Jul 25 '17 at 13:24