Use Notificationmanager in a class that is not Activity

Asked

Viewed 121 times

1

I’m having a little problem and I’m not making it. The problem is this: I have a Fragment in my app, and I want to fire a notification from it. The line I’m having problems with is this: NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

The mistake is in the getSystemService(), IDE tells me that "The method getSystemService(String) is Undefined for the type MinhaClasseFragment "

I’ve tried to take and put together contexts, even use one Context receiving getActivity() and nothing.

I searched the web and couldn’t find anything to help me. What to do?

  • Notificationmanager mNotificationManager = (Notificationmanager) getActivity(). getSystemService(Context.NOTIFICATION_SERVICE); .

  • Gee, I didn’t think of it! Thanks, Helder. I’m still Rookie on Android rs

  • @Helder posts his answer in answer form. So the OP can accept it and everyone will know that the problem is solved. Plus you can earn reputation for it.

  • @Helder Yes, do it :)

1 answer

1


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

Try to do so straight.

  • Quarrel once again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.