gpt4 book ai didi

android - New PendingIntent 更新当前 Intent

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:06:02 25 4
gpt4 key购买 nike

我试图在一段时间间隔后显示不同的通知,但发生的事情是它用新的通知更新当前的 PendingIntent 结果我只收到一个通知,即使我触发 4 - 5 pending Intent 请求

点击按钮我做了以下事情

 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);

}

通知服务.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();
}

请帮我解决这个问题。提前致谢

最佳答案

我找到了

pendingintent 构造函数的第二个参数不应该相同(硬编码为 0)

我将它更改为 (int) System.currentTimeMillis() 以便它不应该相同 :)

Intent ni =new Intent(NotificationService.this,ModifyDatabaseService.class);
ni.putExtra("id", ""+id);
PendingIntent contentIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), ni,
PendingIntent.FLAG_ONE_SHOT);

关于android - New PendingIntent 更新当前 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com