新的 PendingIntent 更新当前意图

2024-03-14

我试图在一段时间间隔后显示不同的通知,但发生的情况是它更新了当前的通知PendingIntent结果,即使我触发 4 - 5 个待处理的意图请求,我也只能收到一个通知

单击按钮后我会执行以下操作

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

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


我找到了

挂起意图构造函数的第二个参数不应该相同(硬编码为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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

新的 PendingIntent 更新当前意图 的相关文章

  • EditText 中的验证允许 IP 或 Web Url 主机

    我需要对我的 EditText 进行验证 以便它允许我输入有效的 IP 地址格式 即示例 132 0 25 225 or 网址格式 www 例如 www example com 逻辑是 如果用户首先输入任何数值 则验证 IP 将执行操作 否
  • 在 Android 中创建和使用 9 补丁图像

    我最近听说了 9 补丁图像 我知道它是 9 平铺的并且是可拉伸的 我想了解更多 如何创建 9 块图像 有什么工具吗 我可以通过 AndroidSDK 或代码创建它吗 9 patch 相对于普通 png 的主要优点 它是否可以根据屏幕动态 自
  • 使用 APDU 命令的有效 NFC 读取比特率是多少?

    我目前正在使用 Android IsoDep trancieve 函数发送和接收累计 1628 字节的数据 该函数分布在 35 个 APDU 命令 选择应用程序 身份验证 读取 中 字节计数包括返回的 MAC 校验和以及由 transcie
  • 我可以在 firebase android 中加载另一个用户个人资料图像吗?

    如果我有其他用户的电子邮件但我以其他用户身份登录 我是否可以加载其他用户的个人资料图像 如果您使用 Firebase Storage 那么从技术上讲是的 它只是一个您可以从中检索任何文件的文件系统 如果不伪造您的应用程序 获取 api 密钥
  • AppCompat v21 工具栏更改徽标大小

    我正在从以前的操作栏迁移到 appcompat v21 中的新工具栏功能 我仍然想将徽标保留在操作栏 工具栏 的左上角 为此 我在布局中添加了支持工具栏 并为其创建了一个新的工具栏 app theme style NewToolBarSty
  • Android Studio:lambda 不起作用[重复]

    这个问题在这里已经有答案了 当尝试使用 lambda 表达式时 我遇到了一些 Gradle 构建错误 错误 41 100 错误 source 1 7 不支持 lambda 表达式 使用 source 8 或更高版本来启用 lambda 表达
  • 访问角落里的存储

    我能找到的与文件存储有关的最接近文档的是这个帖子 http nookdeveloper zendesk com entries 20257971 updated what are the size constraints on my app
  • 如何在 Firebase 远程配置中从 JSON 获取值

    我是 Android 应用开发和 Firebase 的新手 我想知道如何获取存储在 Firebase 远程配置中的 JSONArray 文件中的值 String 和 Int 我使用 Firebase Remote Config 的最终目标是
  • android 确定设备是否采用从右到左的语言/布局

    有没有办法确定设备是否使用从右到左的语言 例如阿拉伯语 而不是从左到右的语言 英语 与较旧的 API 级别 低至 10 兼容的东西是必要的 SOLUTION 我最终在接受的答案中使用了 xml 方法 接下来 我还添加了此处指示的代码 以应对
  • Android ListView setSelection() 似乎不起作用

    我有一个ListActivity实现onListItemClick 并调用doSomething 类的功能 后者包含l setSelection position where l is the ListView object 现在有一个on
  • window.onbeforeunload 在 Android Chrome 上不会触发 [alt.解决方案?]

    我开发了一个简单的聊天应用程序 我正在使用 window onbeforeunload当有人关闭选项卡 浏览器时 基本上是当用户离开房间时 通知其他用户 这是我的代码 scope onExit function scope chatstat
  • Google 移动广告和 Kindle Fire

    我最近用 Google 移动广告替换了 AdMob 库 对此我有一个疑问 广告会出现在 Amazon Kindle Fire 设备上吗 我问这个是因为我知道 Google 移动广告依赖于 Google Play 服务 所以我有点困惑 Goo
  • Android GCM 服务器的 API 密钥

    我有点困惑我应该为 GCM 服务器使用哪个 API 密钥 在文档中它说使用 android api 密钥 这对我不起作用并且总是给出未经授权的 http developer android com google gcm gs html ht
  • 在 AppAuth-Android 中注销

    我有一个用JAVA开发的Android应用程序 对于这个应用程序 我使用的是身份服务器4 https github com IdentityServer IdentityServer4作为我的 STS 一切正常 但我找不到任何注销的实现Ap
  • android 中camera.setParameters 失败

    我已将相机功能包含在我的应用程序中 我还在市场上推出了该应用程序 我从一位用户那里收到一条错误消息 称他在打开相机时遇到错误 我已经在 2 1 的设备上测试了该应用程序 我从用户那里得到的错误是使用 Nexus One 它主要运行 2 2
  • 在 Android 中上传文件出现内存不足错误

    我的上传代码如下 String end r n String twoHyphens String boundary try URL url new URL ActionUrl HttpURLConnection con HttpURLCon
  • Android - iphone 风格 tabhost [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • [cocos2d-x]当我尝试在 Windows 10 中运行“python android-build.py -p 19 cpp-tests”时出现错误

    当我尝试运行命令时python android build p cpp tests 我收到如图所示的错误 在此之前 我收到了另一条关于 Android SDK Tools 版本兼容性的错误消息 所以 我只是将 sdk 版本从 26 0 0
  • 具有矢量可绘制的 ImageView 的 Resources$NotFoundException

    我遇到了崩溃 Resources NotFoundException用于在活动创建时绘制的矢量 21 日前崩溃 安卓工作室2 1 支持库24 0 0 Gradle插件2 1 0 目标SDK 23 最小SDK 15 buildTools版本
  • 异步更新后更新Android Listview

    我正在将 HTTP 调用从同步调用转换为异步调用 由于连接在后台运行 因此当我最初设置列表适配器时 数据不存在 如何在 HTTP 调用后更新列表适配器 我尝试了一些方法 例如在数据发送回之前不设置适配器并再次设置适配器 但没有任何效果 这是

随机推荐