How to start NotificationListenerService?
<p>Today I started writing for android. I want a simple (I think) app that waits for notification with specified title and then does something. I tried this code for service </p>

<pre><code>import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.Toast;


public class NotificationListener extends NotificationListenerService {

Context context;
public int onStartCommand(Intent intent, int flags, int startId) {
    // Let it continue running until it is stopped.
    Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
    return START_STICKY;
}
@Override

public void onCreate() {
    Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show();
    super.onCreate();
    context = getApplicationContext();


}
@Override

public void onNotificationPosted(StatusBarNotification sbn) {


    String pack = sbn.getPackageName();
    Toast.makeText(this,"NOTIFICATION",Toast.LENGTH_SHORT).show();
    String text = "";
    String title = "";
    if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.KITKAT) {
        Bundle extras = extras = sbn.getNotification().extras;
        text = extras.getCharSequence("android.text").toString();
        title = extras.getString("android.title");
    }

    Log.i("Package",pack);
    Log.i("Title",title);
    Log.i("Text",text);

}

@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
    Toast.makeText(this,"NOTIFICATION removed",Toast.LENGTH_SHORT).show();
    Log.i("Msg","Notification was removed");
}
}
</code></pre>

<p>Then added this to manifest:</p>

<pre><code>&lt;service
            android:name=".NotificationListener"
            android:enabled="true"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.service.notification.NotificationListenerService" /&gt;
            &lt;/intent-filter&gt;
        &lt;/service&gt;
</code></pre>

<p>finally started the service in MainActivity onCreate() <code>startService(new Intent(context, NotificationListener.class));</code></p>

<p><strong>onNotificationPosted does not work</strong>. It seems like service was started correctly, because toasts from onStartCommand and onCreate were shown. I tried on emulator and real device. I also allowed notification access in settings. Please help, I wasted 5 hours on that.</p>