Search code examples
androidandroid-fragmentsactionbarsherlockandroid-notifications

NotificationManager in SherlockFragment


My code is for Notification in my App that use SherlockFragment:

Code:

NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

Error:

ERROR: Create constant NOTIFICATION_SERVICE


Solution

  • getSystemService() and NOTIFICATION_SERVICE are defined on Context. Activity inherits from Context, but SherlockFragment does not.

    Change your code to:

    NotificationManager nm = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);