【问题标题】:Android Notification Click to Broadcast Receiver getting same intent stringAndroid Notification Click to Broadcast Receiver 获得相同的意图字符串
【发布时间】:2021-10-07 19:27:17
【问题描述】:

我有一个在通知点击时触发的广播接收器。我正在传递一个字符串以通知广播接收器。字符串的值每次都不同,但是当我测试我的应用程序时,我只能看到我第一次单击通知时收到的值。现在,尽管传递了新值,但我从通知到广播接收器的每个值都是相同的。

我的代码:

//Creating notification
Intent snoozeIntent = new Intent(getApplicationContext(), ServiceLauncherBroadcast.class);
        snoozeIntent.putExtra("order_id", orderId);

//In the broadcast receiver
startWorkManager(intent.getStringExtra("order_id")

//Manifest 
<receiver android:name = ".utils.ServiceLauncherBroadcast" />

【问题讨论】:

    标签: java android


    【解决方案1】:

    请在您的 PendingIntent 中使用此标志:

    PendingIntent.FLAG_CANCEL_CURRENT
    

    【讨论】:

    • 谢谢你,它现在正在工作。我猜这个标志取消了之前的广播并获得了一个新的。
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2023-01-10
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多