【问题标题】:Unique PendingIntent with Manifest declaration带有 Manifest 声明的唯一 PendingIntent
【发布时间】:2015-10-08 20:01:40
【问题描述】:

我正在创建一个 Android 应用程序,它以编程方式创建在应用程序关闭时持续存在的警报。为了让警报持续存在,我必须在我的清单中定义接收器,如下所示:

<receiver
android:name="com.blah.blah.AlarmReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999" >
     <action android:name="com.blah.blah.ALARM" />
</intent-filter>
</receiver>

这是我目前创建 PendingIntents 的方式..

Intent intent = new Intent(ACTION_ALARM);
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager manager = (AlarmManager   (this.getSystemService(Context.ALARM_SERVICE ));

由于我使用常量 ACTION_ALARM,所有警报都连接到同一个 PendingIntent,因此调用 .cancel() 会删除所有警报。但是,我想删除特定的警报实例。我知道创建唯一 PendingIntent 的唯一方法是指定一个唯一操作,这与我在上面定义的清单中的接收器冲突。有没有其他方法可以为我的警报制作可区分的 PendingIntents?我也尝试添加数据,但清单中的接收器似乎没有被触发。

或者,如果我以编程方式为每个警报启动接收器,有没有办法在应用程序关闭时让这些接收器持续存在?

谢谢。

【问题讨论】:

    标签: java android alarmmanager android-pendingintent alarm


    【解决方案1】:

    在这里找到解决方案:How to create different pendingintent so filterEquals() return false?

    使用 PendingIntent.getBroadcast 的第二个参数来建立一个唯一的 PendingIntent。不需要独特的操作,尽管这是我能找到的所有其他帖子的建议。

    现在不知道如何结束这个问题...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多