直接上代码,只要通知的id不一样就可以实现多条通知,也是就是这句notificationManager.notify(mNotificationNum, notification.build());
还有一个问题,服务端一般不会给你返通知id,也不好返,那怎么办???
我是这么处理的,当通知条数超过10条之后把时间最早的那条通知替换掉
/**
* 实现自定义推送声音
* @param context
* @param bundle
*/
private void processCustomMessage(Context context, Bundle bundle) {
mNotificationNum++;
if(mNotificationNum > NOTIFICATION_SHOW_SHOW_AT_MOST) {
mNotificationNum = 1;
}
NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
// String msg = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon_mdpi);
Intent mIntent = new Intent(context,NewsArticleActivity.class);
ThirdView.isReadList = false;
mIntent.putExtra("sex", "");
mIntent.putExtras(bundle);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent)
.setAutoCancel(true);
if (!TextUtils.isEmpty(extras)) {
try {
JSONObject extraJson = new JSONObject(extras);
if (null != extraJson && extraJson.length() > 0) {
String content = extraJson.getString("title");
notification.setContentText(content);
notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.jiguang));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
if(TextUtils.isEmpty(title)) {
title = "";
}
title = title.equals("") ? "" : title;
notification.setContentTitle(title)
.setSmallIcon(R.mipmap.icon_mdpi)
.setLargeIcon(bitmap);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationNum, notification.build());
}