title: How to Check for "enabled_notification_listeners" Programmatically?
body: <p>I need to check that either my application's service is Enabled or Not in <strong>&quot;Notification Access&quot;</strong>.</p>
  <p>I am using this code to check this. The code is running fine on <strong>Nougat</strong>, but it crashes on <strong>Marshmallow</strong>. How can I do that on <strong>Marshmallow</strong>?</p>
  <pre><code>android.provider.Settings.Secure.getString(this.getContentResolver(), &quot;enabled_notification_listeners&quot;).contains(getApplicationContext().getPackageName())
  </code></pre>
  <p>This is the <strong>Error in LogCat</strong>:</p>
  <pre><code>12-06 15:28:02.905 4428-4428/com.inetsoho.app.SkyChat E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.inetsoho.app.SkyChat, PID: 4428
      java.lang.IllegalStateException: Could not execute method for android:onClick
          at android.view.View$DeclaredOnClickListener.onClick(View.java:4740)
          at android.view.View.performClick(View.java:5697)
          at android.view.View$PerformClick.run(View.java:22526)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:158)
          at android.app.ActivityThread.main(ActivityThread.java:7224)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invoke(Native Method)
          at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
          at android.view.View.performClick(View.java:5697) 
          at android.view.View$PerformClick.run(View.java:22526) 
          at android.os.Handler.handleCallback(Handler.java:739) 
          at android.os.Handler.dispatchMessage(Handler.java:95) 
          at android.os.Looper.loop(Looper.java:158) 
          at android.app.ActivityThread.main(ActivityThread.java:7224) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
          at com.inetsoho.app.SkyChat.ui.activities.authorization.LandingActivity.SignUpPhoneNumberOnClickListener(LandingActivity.java:110)
          at java.lang.reflect.Method.invoke(Native Method) 
          at android.view.View$DeclaredOnClickListener.onClick(View.java:4735) 
          at android.view.View.performClick(View.java:5697) 
          at android.view.View$PerformClick.run(View.java:22526) 
          at android.os.Handler.handleCallback(Handler.java:739) 
          at android.os.Handler.dispatchMessage(Handler.java:95) 
          at android.os.Looper.loop(Looper.java:158) 
          at android.app.ActivityThread.main(ActivityThread.java:7224) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  </code></pre>