郭霖:https://blog.csdn.net/guolin_blog/article/details/79854070
public void showNotifictionIcon(Context context, PushBean pushBean) {
? ? mNotificationId = hashCode();
? ? LogUtils.loge("mNotificationId=" + mNotificationId);
? ? Intent broadcastIntent = new Intent(context, NotificationReceiver.class);
? ? broadcastIntent.setAction(Intent.ACTION_VIEW);
? ? broadcastIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
? ? broadcastIntent.putExtra(AppConstant.PUSH_TYPE, pushBean);
? ? PendingIntent pendingIntent = PendingIntent.
? ? ? ? ? ? getBroadcast(context, 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
? ? NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
? ? if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
? ? ? ? builder.setSmallIcon(R.drawable.logo);
? ? } else {
? ? ? ? builder.setSmallIcon(R.drawable.logo);
? ? }
? ? builder.setContentTitle(pushBean.getTitle())
? ? ? ? ? ? .setTicker(pushBean.getDescription())
? ? ? ? ? ? .setContentIntent(pendingIntent)
? ? ? ? ? ? .setChannelId("zhuhai")//適配8.0
? ? ? ? ? ? .setAutoCancel(true)//用戶點擊就自動消失
? ? ? ? ? ? .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo));
? ? //適配8.0
? ? NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
? ? if(Build.VERSION.SDK_INT >= 26){
? ? ? ? NotificationChannel channel = new NotificationChannel("zhuhai", getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
? ? ? ? builder.setChannelId("zhuhai");
? ? ? ? manager.createNotificationChannel(channel);
? ? }
? ? manager.notify(mNotificationId, builder.build());//每次改變mNotificationId的值才能在通知欄產生蓋樓的效果
}