通知Android的? [英] Notification android?

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

问题描述

我的Andr​​oid programming.I的新手,想知道可以在这样的时间显示通知,时间格式字符串(2014年1月10日1时30分33秒)?每当应用程序正在运行或不它给有关(2014年1月1日1时30分33秒),并展示在2014年1月10日1时30分33秒。 \\

I'm newbie of android programming.I want to know can show notification at a time like that ,Time format String(2014-1-10 1:30:33)? It's given about (2014-1-1 1:30:33) and show at 2014-1-10 1:30:33 whenever the app is running or not. \

  public void Notification(String s)
{
        String ns = Context.NOTIFICATION_SERVICE;

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

        int icon = R.drawable.notification_icon;
        CharSequence tickerText = "Ready for Play time."; // ticker-text
        long when = System.currentTimeMillis();
        Context context = getApplicationContext();
        CharSequence contentTitle = "Play Time";
        CharSequence contentText = "Your match is at "+s;

        Intent notificationIntent = new Intent(this,ScheldueNotification .class);
        //PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification(icon, tickerText, when);
        notification.setLatestEventInfo(context, contentTitle, contentText, pendingNotificationIntent);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        // and this

        mNotificationManager.notify(MY_NOTIFICATION_ID, notification);

        Intent myIntent = new Intent(MainActivity.this, myReceiver.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);

          AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");

          /*java.util.Date date;
                try {
                    date = formatter.parse(getCurrentTime());
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }*/


          try {
              alarmManager.set(AlarmManager.RTC,(sdf.parse(getCurrentTime())).getTime(), pendingIntent);
          } catch (java.text.ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }

        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.vibrate = new long[] { 0, 100, 200, 300 };
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        //alert();

}

编辑:在这里,在我的code。都不尽如人意。

Here in my code. Not working well.

推荐答案

您可以使用报警管理器,为。
请参阅亚历山大Fragotsis答案在链接。

You can use Alarm Manager for that. Refer to Alexander Fragotsis answer on this link.

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

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