通知在CountDownTimer结束 [英] Notification at end of CountDownTimer

查看:137
本文介绍了通知在CountDownTimer结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让通知告诉我,我的 CountDownTimer 已经结束,但遇到了一些麻烦IM。目前,我已经建立只是一个测试通知(我认为),但我不知道如何调用该通知工作。以下是我目前所面对的:

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

这是调用一次定时器= 0,我想知道,如果可能,呼吁当它通知。

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

在此先感谢您的帮助,如果您需要更多的code随意问。

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

推荐答案

为了使您需要致电通知的PendingIntent 这样的通知将工作。

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

试试这个在 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);
             }

这篇关于通知在CountDownTimer结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆