代码之家  ›  专栏  ›  技术社区  ›  Chander Shivdasani

Android:在状态栏中管理多个通知

  •  6
  • Chander Shivdasani  · 技术社区  · 15 年前

    private void updateNotification(int notificationId, int clockStatusID, CharSequence text) {
       // notificationManager.cancel(notificationId);
        // throws up an ongoing notification that the timer is running
        Log.i("TIMERCOUNT", "Notification id: " + notificationId);
        Notification not = new Notification(clockStatusID, // the
            // icon
            // for
            // the
            // status
            // bar
            text, // the text to display in the ticker
            System.currentTimeMillis() // the timestamp for the
            // notification to appear
        );
        Intent intent = new Intent();
        intent.setClassName("com.intuit.time_catcher.android.activities",
        "com.intuit.time_catcher.android.activities.Tabs");
        not.setLatestEventInfo(self,
            getText(R.string.timer_notification_title),
            getText(R.string.timer_on_notification_text), PendingIntent
            .getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT));
        not.flags += Notification.FLAG_ONGOING_EVENT;
        not.flags += Notification.FLAG_NO_CLEAR;
        notificationManager.notify(notificationId, not);
    
    }
    

    下面是我面临的问题。 假设状态栏中有3个正在运行的计时器和3个通知。当我更新定时器2时,通知3(在最右边)会被更新,但我真正想做的是更新第二个通知(中间的一个)。 当我打印通知id时,我看到了正确的值。

    2 回复  |  直到 15 年前
        1
  •  4
  •   Community Mohan Dere    9 年前

    听起来像是缓存了您的意图(这是出厂默认值)

    尝试添加唯一的 setAction('anystring'+timestamp) 或者一个计数值,它必须是唯一的,如本文所述 question

    intent.setAction("actionstring" + System.currentTimeMillis());
    
        2
  •  1
  •   hackbod    15 年前

    应用程序不能直接控制订单通知显示在。。。你只是看到他们给你重新订购了吗?