String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.notification_icon;       
CharSequence tickerText = "Hello"; 
long when = System.currentTimeMillis();
Context context = getApplicationContext();      
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);//点击通知时转移内容
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(id,notification); 
通过上面代码可以用Notification往状态栏上发送通知信息,点击某条通知后转到MyClass
想知道如何在MyClass中查看具体某条通知内容呢?

解决方案 »

  1.   

    在Notification提示的同时,将接收的数据写入文件,或者数据库中!用Notification启动Activity时,读取文件或数据库中的内容就行啊!!
      

  2.   

    你好,感谢你的回答,但是如果一次收到多条通知后。当你点击某条通知时 ,在Notification启动Activity时你如何知道是点击了哪一条通知并显示呢?
      

  3.   

    其实可以直接传递你接收的数据到Activity!
    把数据放到这个notificationIntent里传递!
    notificationIntent.putExtra(.....);Intent notificationIntent = new Intent(this, MyClass.class);//点击通知时转移内容
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(id,notification);  
      

  4.   


    问题解决了,notificationIntent.putExtra(.....);这段代码我放错位置了。
    之前我放到PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);这段后面去了。只要放到前面就可以了。然后在另外一个activity中getIntent().getStringExtra("**")就可以了。呵呵
      

  5.   

    能否监听到状态栏里 我点击的是哪个Notification(在收到多个类似的Notification的情况下)。