Issue
I am trying to create a notification in a fragment. I am having errors. Can any help ?
Here is my code
NotificationManager notification = (Notification) getSystemService(getActivity().NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "your daily tip";
long when System.currentTimeMillis();
Context context = getActivity();
CharSequence contentTitle = "AutoKit";
CharSequence = contentText = "hi";
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contextTitle, contentText, contentIntent);
notificationManager.notify(1, notification);
The error lies in the first line.
Solution
Change your first line with this one, should do the trick :
NotificationManager notification = ( NotificationManager ) getActivity().getSystemService( getActivity().NOTIFICATION_SERVICE );
Answered By - Julien Revault d'A...
Answer Checked By - David Marino (JavaFixing Volunteer)