读书人

关于在通报显示通知

发布时间: 2012-09-14 23:00:49 作者: rapoo

关于在通知显示通知

?

@Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);

?

?NotificationManager notificationMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

?

?

Notification notification = new Notificatio(drawable,tickerText,System.currentTimeMillis()); //此处定义了一个Notification ,其中第一个参数代表图标

第二个参数代表提示的内容,第三个参数是指要显示的时间,一般是当即显示,故填入系统当前时间。

?

?

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ActivityMain.class), 0);

//该语句的作用是定义了一个不是当即显示的activity,只有当用户拉下notify显示列表,并且单击对应的项的时候,才会触发系统跳转到该activity.

??

notification.setLatestEventInfo(this, title, content, contentIntent);

?

//在此处设置在nority列表里显示的标题和样式。

?

//此处的NOTIFICATIONS_ID是为此通知指定一个id它是全局唯一的,方便以后引用

??

mNotificationManager.notify(NOTIFICATIONS_ID, notification);

?

?

?

?

?

?

读书人网 >移动开发

热点推荐