0

I am trying to make notification to tell me that my CountDownTimer has ended, But im having some trouble. At the moment i have established just a test notification (i think) But i don't know how to call for the notification to work. Here is what i have at the moment:

public void onFinish() {
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(TestTimer.this);
      mBuilder.setContentTitle("Notification Alert, Click Me!");
      mBuilder.setContentText("Hi, This is Android Notification Detail!");
     TextView timer=(TextView)findViewById(R.id.mTextField);
    timer.setText("Seconds remaining: 0 ")

This is called once the timer = 0, and i want to know if its possible to call for a notification when it does.

Thanks in advance for any help, If you need any more code feel free to ask.

Teh john
  • 41
  • 11
  • The builder needs a `PendingIntent` set via `setContentIntent` and then use the `NotificationManager`'s `notify` method to send the notification. –  Jun 14 '14 at 15:12

1 Answers1

5

To enable notification you need to call PendingIntent so notification will work.

try this in your onFinish

 public void onFinish() {
                 NotificationManager  notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                 Notification  myNotification = new Notification(R.drawable.ic_launcher, "Notification!", System.currentTimeMillis());
                    Context context = getApplicationContext();
                    String notificationTitle = "Exercise of Notification!";
                    String notificationText = "http://android-er.blogspot.com/";
                    Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
                    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,   myIntent, Intent.FILL_IN_ACTION);
                    myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
                    myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
                    notificationManager.notify(1, myNotification);
             }
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • 1
    It is worth nothing that in the `notify` command, the "1" in the code above indicates the message id. Changing that will allow multiple messages to be posted whereas keeping it the same overwrites the previous notification's information. –  Jun 14 '14 at 15:19