通知 notification

来源:互联网 发布:淘宝上怎么买域名 编辑:程序博客网 时间:2024/05/21 20:25

一、通知基本信息

通知是指显示在通知抽屉上的信息条目;

二、Notification对象至少具备:

首次显示通知信息时,在状态栏上显示的ticker text;

ticker text消失后,在状态栏上显示的图标;

代表通知信息自身,在通知抽屉里显示的视图;

用户点击抽屉中的通知信息,触发PendingIntent.

三、发送通知

NotificationManager的notify(int,Notification)

四、实例

Resources r=getResources();
            PendingIntent pi=PendingIntent.getActivities(this,0, new Intent[]{new Intent(this, PhotoGalleryActivity.class)},0);
            Notification notification=new NotificationCompat.Builder(this).setTicker(r.getString(R.string.new_pictures_title))
                    .setSmallIcon(android.R.drawable.ic_menu_report_image)
                    .setContentTitle(r.getString(R.string.new_pictures_title))
                    .setContentText(r.getString(R.string.new_pictures_text))
                    .setContentIntent(pi)
                    .setAutoCancel(true)
                    .build();
            NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(0,notification);


0 0
原创粉丝点击