在按home键时 实现通知栏  上显示对应程序图标和文字,
然后点击该通知栏图标通过intent自动返回进入原来的activity
 请问如果多个activity 怎么实现每一个activity对应的通知栏每个activity都添加一个通知Notification是可以实现,但是如果activity很多的话 有没有好一点的方法呢

解决方案 »

  1.   

    // 创建一个NotificationManager的引用
            NotificationManager notificationManager = (NotificationManager)getSystemService(android.content.Context.NOTIFICATION_SERVICE);
            
            // 定义Notification的各种属性
            Notification notification = new Notification(R.drawable.taskbar_icon,
                    "AndroidUltrasound在后台运行……", System.currentTimeMillis());
            notification.flags |= Notification.FLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中
            notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
            notification.flags |= Notification.FLAG_SHOW_LIGHTS;
            notification.defaults = Notification.DEFAULT_LIGHTS;
            notification.ledARGB = Color.BLUE;
            notification.ledOnMS = 5000;
                   
            // 设置通知的事件消息
            CharSequence contentTitle = "AndroidUltrasound"; // 通知栏标题
            CharSequence contentText = "超声程序正在运行"; // 通知栏内容
            
            Context context = getApplicationContext(); 
            System.out.println("Notification--->");
            Intent notificationIntent = new Intent(context, AndroidUltrasound.class); // 点击该通知后要跳转的Activity
            PendingIntent contentItent = PendingIntent.getActivity(context, 0,
                    notificationIntent, 0);
            notification.setLatestEventInfo(context, contentTitle, contentText,
                    contentItent);        // 把Notification传递给NotificationManager
            notificationManager.notify(0, notification);
      

  2.   

    您好,我想问一下。实现通知栏上显示对应图标和文字,
    我想实现点击某条通知后在另外一个activity来显示具体的通知信息。
    但是如何在activity中取到选择的具体某一条通知信息呢?
      

  3.   

    想请教一下如何在”AndroidUltrasound“中显示状态栏中的通知呢?
      

  4.   

    搜索下NotificationManager  资料一大片
      

  5.   


    看下NotificationManagerService的源码,里面已经实现了,当点击click某个通知消息时,会响应启动相应的程序