Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialleo you
1,723 Pointsit kept asking Make sure you call 'getSystemService()' from the context., but i already used it in the code
i have used
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)
to create the NotificationManager
public class DistressCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Add your code here!
Notification.Builder notificationBuilder = new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_distress)
.setContentTitle("Incoming Distress Signal")
.setContentText("A distress call has been received from somewhere in space and time.");
Notification notification = notificationBuilder.build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE);
}
}
1 Answer
Anglebert Masunda
6,406 PointsSpecify the context for your getSystemService method first. i.e
public class DistressCallReceiver extends BroadcastReceiver { private NotificationManager mNotificationManager; @Override public void onReceive(Context context, Intent intent) { // Add your code here! Notification.Builder notificationBuilder = new Notification.Builder(context) .setSmallIcon( R.drawable.ic_distress) .setContentTitle("Incoming Distress Signal") .setContentText("A distress call has been received from somewhere in space and time."); Notification notification = notificationBuilder.build();
mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
}
cory brighton
10,215 Pointscory brighton
10,215 Pointsit means that you have to call getSystemService() from context NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)