1

I am attempting to show a basic notification from a fragment in an ActionBarSherlock layout. I have been following the tutorial here as well as the one on the Android Developer pages, but I am getting the error 'Cannot resolve method 'build()' on the last line. I have imported android.support.v4.app.NotificationCompat and .app.NotificationManager

public void createNotification(){

    NotificationManager mNotificationManager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getActivity());
    mBuilder.setSmallIcon(R.drawable.icon);
    mBuilder.setContentTitle("Title");
    mBuilder.setContentText("Text");
    mBuilder.setTicker("Ticker");
    mNotificationManager.notify(1,mBuilder.build());
}

If I change the last line to mNotificationManager.notify(1,mBuilder.getNotification()); it works. Why is this?

tallpaul
  • 1,220
  • 2
  • 13
  • 35

1 Answers1

1

It worked with me for both build() and getNotification() . FYI , Notification.Builder.build() is API level 16 so check your target. Also check your imports and build paths and clean the project. If the problem persists try another android-support-v4.jar inside libs may be its corrupted.

Hope this helps.

youssefhassan
  • 1,067
  • 2
  • 11
  • 17
  • Thanks, I'll try your suggestions, I'm set as API level 16. I have updated the question as I am using ActionBarSherlock, just in case it makes a difference. – tallpaul Jan 22 '14 at 21:47