新PendingIntent更新当前的意图 [英] New PendingIntent updates current intent

查看:118
本文介绍了新PendingIntent更新当前的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一定时间间隔后表现出不同的通知,但发生的事情是它更新当前的 PendingIntent 被新的,结果我得到的只是一个通知,即使我火了4 - 5挂起的意图请求

i am trying to show different notifications after some time interval but what happens is it updates the current PendingIntent by the new one as a result i get only single notification even if i fire 4 - 5 pending intents requests

在按钮单击我做下面的事情

On button click i do the following thing

 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

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

 }

NotificationService.java

NotificationService.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帮我这个.thanks提前

plaese help me out with this .thanks in advance

推荐答案

如果ID的 nm.notify值(ID,notif); 是一样的,然后通知将被覆盖。

If the value of id in nm.notify(id, notif); is same then the Notification will be overwritten.

所以,你需要确保该ID是不同的通知不同的

So you need to make sure that the id is different for different Notification

这篇关于新PendingIntent更新当前的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆