新的 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 更新当前意图 的相关文章

  • 无法在 OSX 上使用 eclipse for android 链接到 cocos2dx

    我以前从来没有花这么多时间来初始设置开发环境 这有点荒谬 我正在尝试运行cocos2dx附带的演示代码 我在用着 ADK 附带的 eclipse 风格 cocos2d 2 1beta3 x 2 1 0 ndk r8c 我尝试使用 creat
  • 如何更改Android应用程序的页面?

    我是安卓新手 我已经设计了由许多页面组成的应用程序 任何人都有源代码或任何可以让我知道如何构建它的东西 例如 当我单击按钮时 我希望它将页面更改为下一页 谢谢你卡 运行通过第一个应用程序教程 https developer android
  • ListView 滚动时隐藏和显示浮动按钮

    我正在我的应用程序中创建一个 listView 和一个浮动按钮 我希望根据滚动状态实现隐藏和返回的效果 当 的时候ListView滚动时按钮隐藏得很好 但是当滚动停止时按钮不会返回到其初始位置 有任何想法吗 My Code public c
  • 具有多个 orderBy 的 Android firebase 查询

    我想检索我的 firebase 数据库中所有类型为 福音 的数据 这是我的数据库 DatabaseReference infoRef FirebaseDatabase getInstance geReference child info i
  • 尝试查找 BLE 设备时如何使用 LeDeviceListAdapter?

    我正在 Android 中开发一个应用程序 并且我遵循 Android 中的代码建议开发者页面 http developer android com guide topics connectivity bluetooth le html f
  • 空 Activity 中的内存泄漏

    我最近决定使用泄漏金丝雀 https github com square leakcanary在我的项目中 所以我创建了一个空的项目Activity只是为了测试 当我运行应用程序时 在没有逻辑代码或视图的项目创建之后 我从这个库中获得了内存
  • 在 Android Webview 中加载 Angular JS 网站的问题

    大家好我正在尝试加载GTV http gtvqa com Android WebView 中 它在移动浏览器中加载得很好 但在 webview 中则不行 这是我的代码 WebView theWebPage new WebView this
  • 从滚动视图返回子视图

    我有一个父母ScrollView带有儿童视图 当用户按下后退按钮时 我希望子视图处理该事件 我尝试了一些方法 但似乎都不起作用 按后退按钮会终止活动 public class GameScrollView extends ScrollVie
  • Chrome 崩溃:尝试在空对象引用上调用虚拟方法“long android.view.accessibility.AccessibilityNodeInfo.getSourceNodeId()”

    在处理网页的搜索表单 JavaScript CSS HTML 时 每次单击网络搜索图标并且输入字段获得焦点时 Chrome 浏览器 Android 10 都会崩溃 崩溃报告中的调试堆栈跟踪显示 Attempt to invoke virtu
  • android - 定期轮询服务器并将响应显示为通知[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我正在构建一个Android应用程序 我需要每三个小时从服务器获取一些通知数据 文本 并使用NotificationManager将其
  • SwipeListView 47 度:以编程方式滑动第一项

    我想滑动第一个项目滑动列表视图 https github com 47deg android swipelistview on Activity启动以向用户显示SwipeListView是可滑动的 如何使用此 UI 元素以编程方式执行此操作
  • 减少 android studio 2.1 构建时间

    我之前使用的是 android studio 1 5 刚刚升级到 2 1 但是更新后我的构建花费了更多时间 从 15 秒到现在 2 分钟 我已经尝试过的事情如上所述 在 设置 中启用离线工作 org gradle daemon true o
  • 如何检测 Android 设备是否与 Android Wear 手表配对

    我正在创建一个 Android Wear 应用程序来扩展推送通知 当收到推送通知时 我的应用程序会从服务器下载大约 10 张图像 并在手表上显示这些附加图像 这些图像特定于 Android Wear 应用程序 不会显示在手持设备上 如何判断
  • 改造2:使用json对象发送文件

    我在请求正文中发送对象 如下所示 title test description test images POST create data Call
  • 在 Java/Android 中查找 UTF-8 字符串中的字符数

    我试图找出字符串以 UTF 8 存储时的长度 我尝试了以下方法 String str Charset UTF8 CHARSET Charset forName UTF 8 byte abc str getBytes UTF8 CHARSET
  • RecyclerView onItemClickListener 不工作

    我正在研究回收视图并尝试对 recyclerview 的每个项目使用点击侦听器界面 这是我的活动课程 public class LegacyHomeActivity extends ActivityBaseDrawer private Li
  • Android:iOS UIActionSheet 等效项

    我正在转换一个 iOS 应用程序 并且需要实现从 iOS 到 Android 的 UIActionSheet 的等效项 什么 UI 元素最能模仿这一点 我的目标是 Android 2 2 及更高版本 您将使用 AlertDialog 或 D
  • 如何执行graph-api Facebook Android SDK来上传照片并标记人物?

    如何执行graph api Facebook Android SDK来上传照片并标记人物 在网络上 对于 Android 版 facebook sdk 有很多混淆 我的第一个方法 Bitmap img bitmap if img null
  • 在 RadioButton 旁边添加 EditText

    我有一个习惯DialogPreference我想在其中有一个子类RadioGroup与三个单选按钮 前两个是香草RadioButton带有标题的组件 但对于第三个我想放置一个EditText直接在它的右侧 这样当选择该按钮时我可以输入自定义
  • 注意通知持续时间

    是否可以将抬头通知的持续时间设置为无限 现在它只显示 5 秒 已经尝试过不同的事情 例如更改类别 但持续时间始终为 5 秒 这是我的代码 Notification notification notificationBuilder setCa

随机推荐