gpt4 book ai didi

android - 带有 BroadCastReceiver 的 AlarmManager : Programed two alarms but received only one

转载 作者:行者123 更新时间:2023-11-30 01:12:37 24 4
gpt4 key购买 nike

我有两个闹钟和一个广播接收器:

AlarmManager am2=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent2 = new Intent(context, MyReceiverAlarm.class);
intent2.putExtra("name", "juan");
PendingIntent pi2 = PendingIntent.getBroadcast(context, 0, intent2, 0);

am2.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+1000, pi2);



AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyReceiverAlarm.class);
intent.putExtra("name", "jose");
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+8000, pi);

但是,我总是只收到第一个。我总是得到“juan”并且警报在 8 秒后触发。我不明白原因...如果我有两个警报,为什么触发一个?

我的广播接收器:

Toast.makeText(context, extras.getString("nombre") + "", Toast.LENGTH_LONG).show();
String name=extras.getString("nombre");
if (extras != null && name.equals("juan") {
String callForwardString = PHONE ;
Intent intentCallForward = new Intent(Intent.ACTION_CALL);

Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
intentCallForward.setData(uri2);
intentCallForward.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(intentCallForward);
} else {
...
}

不可能设置两个闹钟吗?

提前致谢

最佳答案

尝试更改请求代码(传递给getBroadcast()的第二个参数:

PendingIntent pi2 = PendingIntent.getBroadcast(context, 2, intent2, 0);
PendingIntent pi = PendingIntent.getBroadcast(context, 1, intent, 0);

关于android - 带有 BroadCastReceiver 的 AlarmManager : Programed two alarms but received only one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38271405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com