我会尝试每次使用不同的参数创建多本地通知,这是我创建通知的代码:
public void setNotficition(int Time,String ProdName,String ProdDesc,String ProdID){
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
notificationIntent.addCategory("android.intent.category.DEFAULT");
notificationIntent.putExtra("ProdName",ProdName);
notificationIntent.putExtra("ProdDesc",ProdDesc);
notificationIntent.putExtra("ProdID",ProdID);
PendingIntent broadcast = PendingIntent.getBroadcast(this, 100, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, Time);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),broadcast);
}
这是我的BroadcastReceiver代码:
@Override
public void onReceive(Context context, Intent intent) {
String ProdName= intent.getStringExtra("ProdName");
String ProdDesc= intent.getStringExtra("ProdDesc");
String ProdID= intent.getStringExtra("ProdID");
int ID = Integer.parseInt(ProdID);
Intent notificationIntent = new Intent(context, NotificationActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(NotificationActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
Notification notification = builder.setContentTitle(ProdName)
.setContentText(ProdDesc)
.setTicker("New Message Alert!")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent).build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), notification);
}
每次接听最后一次电话
答案 0 :(得分:2)
通知id
在您的应用中应该是唯一的。
如果您的帐户已发布了具有相同
id
的通知 申请并没有被取消,它将被取代 更新的信息。
NotificationManager notiManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notiManager.notify(UNIQUE_ID, notification);
如果您使用的是PendingIntent.getBroadcast()
方法,请使用不同的requestCode
进行不同的通知:
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
notificationIntent.addCategory("android.intent.category.DEFAULT");
notificationIntent.putExtra("ProdName",ProdName);
notificationIntent.putExtra("ProdDesc",ProdDesc);
notificationIntent.putExtra("ProdID",ProdID);
PendingIntent broadcast = PendingIntent.getBroadcast(this, REQUEST_CODE, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
希望这会有所帮助!
答案 1 :(得分:1)
您可以通过每次更改通知ID来创建多个通知。
PendingIntent broadcast = PendingIntent.getBroadcast(this, 100, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
getBroadcast呼叫的第二个参数是"通知ID" (在你的情况下是100)。如果生成多个通知,只需使用不同的不同通知ID。
希望它会对你有所帮助: - )
答案 2 :(得分:0)
创建通知并链接到id,此ID可用于修改或更新现有通知,天气您正在改变意图或仅仅是堆栈的行为。