弹出通知

来源:互联网 发布:中美大都会 知乎 编辑:程序博客网 时间:2024/05/17 08:12



设置回调Intent

case SNSParam.NEWS_TYPE_INFO_CHAT://个人聊天


Intent chatIntent = new Intent(context, FriendMainTab.class);
chatIntent.putExtra(FriendMainTab.EXTRA_INDEX,FriendMainTab.TAB_CONVER);
StringBuffer chatBuffer = new StringBuffer();
chatBuffer.append(msg.getFromUser()).append(":").append(contentString);
showNotification(msg, context, chatBuffer.toString(),chatIntent, MOOD_SELF);


break;
case SNSParam.NEWS_TYPE_CIRCLE_CHAT://圈子


Intent circlemsg = new Intent(context, CricleMessgeActivity.class);
circlemsg.putExtra(MeettingMsgActivity.userids, msg.getFromId());
circlemsg.putExtra(MeettingMsgActivity.userNames, msg.getCircleName());
circlemsg.putExtra(MeettingMsgActivity.ISACTION, false);
StringBuffer circleBuffer = new StringBuffer();
circleBuffer.append(msg.getCircleName()).append(":").append(contentString);
showNotification(msg, context, circleBuffer.toString(), circlemsg,MOOD_SELF);


break;



/**

* 弹出通知
public class ActNotifyDemo extends Activity {
    Button _btn1;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


 
        _btn1 = (Button)findViewById(R.id.button1);
        _btn1.setOnClickListener(new OnClickListener(){
            //触发通知
            public void onClick(View arg0) {
                //获得通知管理器
                 NotificationManager manager = (NotificationManager) getSystemService(
                         Context.NOTIFICATION_SERVICE); 
                 //构建一个通知对象
                 Notification notification = new Notification(R.drawable.icon, 
                            "通知", System.currentTimeMillis()); 


                 PendingIntent pendingIntent = PendingIntent.getActivity( 
                         ActNotifyDemo.this, 

                         new Intent(ActNotifyDemo.this,ActNotifyDemo.class),


                 );
                 
                 notification.setLatestEventInfo(getApplicationContext(),
                         "通知标题", 
                         "通知显示的内容", 
                         pendingIntent);
                 notification.flags|=Notification.FLAG_AUTO_CANCEL; //自动终止
                 notification.defaults |= Notification.DEFAULT_SOUND; //默认声音
                 manager.notify(0, notification);//发起通知
            }
        });
    }
}