How to check if my app is allowed to show notification

后端 未结 6 1028
执念已碎
执念已碎 2020-12-05 06:49

In Android settings users can turn off notification if they don\'t want to. So is there any method that like isNotificationAllowed() to check is my app is allow

6条回答
  •  难免孤独
    2020-12-05 07:07

    Try this:

    if (Settings.Secure.getString(getActivity().getContentResolver(), "enabled_notification_listeners").contains(getActivity().getPackageName())) {
        // Notification access service already enabled
        Toast.makeText(getActivity(),"notification enabled",Toast.LENGTH_LONG).show();
    } else {
        Intent intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.Settings$AppNotificationSettingsActivity");
        intent.putExtra("app_package", getPackageName());
        intent.putExtra("app_uid", getApplicationInfo().uid);
        startActivity(intent);
    }
    

提交回复
热议问题