读书人

Notification 的应用

发布时间: 2012-09-27 11:11:17 作者: rapoo

Notification 的使用

NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);// Set the icon, scrolling text and timestamp  设置可以在状态栏上显示的图标和提示信息      Notification notification = new Notification(R.drawable.stat_sample, text,                    System.currentTimeMillis());// The PendingIntent to launch our activity if the user selects this notification//用户在状态栏点击相应的notify可以发送的Intent(连接到相应的activity)            PendingIntent contentIntent = PendingIntent.getActivity(this, 0,                    new Intent(this, ForegroundServiceController.class), 0);// Set the info for the views that show in the notification panel.//状态栏的notify展开后显示的文本信息            notification.setLatestEventInfo(this, getText(R.string.local_service_label),                           text, contentIntent);mNM.notify(R.string.foreground_service_started, notification);//使用R.string.foreground_service_started 是因为它是一个唯一ID//取消notifymNM.cancel(id);//id=R.string.foreground_service_started 之前定义的一个唯一ID



读书人网 >移动开发

热点推荐