5

I have class derived from NotificationListenerService and it is getting created and started for me automatically when the app starts. However I would like to lazily start the service later from an activity and not have it start automatically when the app starts. Is it possible to do this? The manifest is:

    <service android:name=".MyNotificationListener"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>

NOTE that before NotificationListenerService can be used the user has to grant the app notification access via the setting. However if the intent filter is removed from the manifest then the app does not appear in the settings and thus the user is unable to grant permission, so without permission the service can't be started. Seems like the OS needs that intent filter to be there before it will display the app in the settings.

UPDATE: The documentation for BIND_NOTIFICATION_LISTENER_SERVICE says:

Must be required by an NotificationListenerService, to ensure that only the system can bind to it.

So I guess that means only the OS can start NotificationListenerService and nobody else can.

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

-1

Yes. Create an Intent for the service then call startService.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • How should I change the manifest to prevent it starting automatically? – Gruntcakes Apr 01 '15 at 18:12
  • Remove the intent filter. – Gabe Sechan Apr 01 '15 at 18:13
  • Before NotificationListenerService can be used the user has to grant the app notification access via the setting. However if the intent filter is removed from the manifest then the app does not appear in the settings and thus the user is unable to grant permission, so without permission the service can't be started. Seems like the OS needs that intent filter to be there before it will display the app in the settings. – Gruntcakes Apr 01 '15 at 18:29