Tôi đang cố gắng hiển thị các thông báo khác nhau sau một khoảng thời gian nhưng điều gì xảy ra là nó cập nhật PendingIntent
hiện tại bằng kết quả mới.Mục mới PendingIntent cập nhật ý định hiện tại
Mở nút bấm tôi làm những điều sau đây
try{
adapter.OpenDB();
int id = adapter.getMaxId("reminder")+1;
adapter.CloseDB();
Intent intent = new Intent(MilestonesActivity.this, AlarmReceiver.class);
intent.putExtra("message", ""+editMsg.getText()+" "+editDate.getText());
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MilestonesActivity.this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP,
reminddate.getTimeInMillis(), pendingIntent);
adapter.CloseDB();
}catch (Exception e) {
// TODO: handle exception
}
AlarmReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
Intent i =new Intent(context, NotificationService.class);
try{
int id = intent.getExtras().getInt("id");
i.putExtra("id", id);
CharSequence message = intent.getExtras().getString("message");
i.putExtra("message", message);
}catch (Exception e) {
// TODO: handle exception
}
context.startService(i);
}
Notificatio nService.java
public void show(Intent intent) {
try{
NotificationManager nm;
Log.e("recieve", "ok");
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Lawyer app Reminder";
CharSequence message = intent.getExtras().getString("message");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(),
PendingIntent.FLAG_ONE_SHOT);// also tried FLAG_UPDATE_CURRENT
int id =intent.getExtras().getInt("id");
Log.e("I", ""+id);
Notification notif = new Notification(R.drawable.message_active,
"Lawyer app Reminder.", System.currentTimeMillis());
notif.defaults = Notification.DEFAULT_ALL;
notif.flags = Notification.FLAG_AUTO_CANCEL;
notif.setLatestEventInfo(this, from, message, contentIntent);
nm.notify(id, notif);
}catch (Exception e) {
e.printStackTrace();
}
plaese giúp tôi ra với điều này .thanks trước
có id khác nhau mỗi lần và khi tôi kích hoạt yêu cầu đầu tiên được kích hoạt sau 2 phút và giây sau 3 phút thì sẽ hiển thị thông báo đơn sau 3 phút không sau 2 phút như cập nhật này. – Mahesh