CountDownTimer结束时的通知

时间:2014-06-14 14:57:13

标签: android notifications

我正在尝试通知告诉我我的CountDownTimer已经结束,但我遇到了一些麻烦。目前我已经建立了一个测试通知(我认为)但我不知道如何调用通知工作。这就是我现在所拥有的:

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 ")

一旦计时器= 0,就会调用它,我想知道是否有可能在通知时调用通知。

预先感谢您提供任何帮助,如果您需要更多代码,请随时提出。

1 个答案:

答案 0 :(得分:5)

要启用通知,您需要致电PendingIntent,以便通知正常。

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);
             }