Android创建并更新通知栏通知

id为通知的唯一标识,如果多次创建id相同的通知,则只保留最后一次创建的通知。更新通知也是采用这个机制来实现的。
 
  
 
  
    void showNotification(int id, String title, String subText, int progress) {
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
        mBuilder.setContentTitle(title);
        mBuilder.setContentText(subText);
        mBuilder.setSmallIcon(R.mipmap.ic_launcher);
        mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
        mBuilder.setProgress(100, progress, false);
        Notification notification = mBuilder.build();
        mNotificationManager.notify(id, notification);
    }


你可能感兴趣的:(Android)