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 trial

Android Intents and Broadcast Receivers Local Notifications Creating a Local Notification

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

**[SOLVED]** Always the simplest thing to trip me up... So, some help, please.

Task 5 of 5.

I've tried many things and have read the Docs so many times, I can probably recite them. :confused:

No hints, please. I know the problem is the last line of included code... I know it's something simple I am missing... I just can't figure what.

Ben Jakuben

DistressCallReceiver.java
public class DistressCallReceiver extends BroadcastReceiver {

  private NotificationManager notificationManager;

    @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();

      context.getSystemService(Context.NOTIFICATION_SERVICE);
      notification.notify(32, notificationBuilder); //the problem is here

    }
}
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Well,

After more than a few hours on Google and Stack Overflow, I figured the problem comes from Task 4. What I had entered for Task 4 should not have passed the challenge, as it was NOT the correct code. Where I had

context.getSystemService(Context.NOTIFICATION_SERVICE);

It should have been

NotificationManager notificationManager = (NotificationManager)
        context.getSystemService(Context.NOTIFICATION_SERVICE);

As we specifically needed a NotificationManager variable to use for the next Challenge.

From there, Task 5 is simple! Call the method to notify with an int as the first argument and notification for the second (Straight from the Docs). Once you actually have a notificationManager variable to use... You get

notificationManager.notify(0, notification);

Simple solution that I understand, but only when you have the right code after the 4th Task

Ben Jakuben, could you please check Task 4...and why my (now obvious) incorrect code passed... it could've saved me about 3 hours of banging my head against the wall. Lol. :) :dizzy:

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Ouch - sorry about that! I'll have to dig and see if I can find a bug or explanation. Thanks for the heads up!