我正在使用2个单独的闹钟。我的课程中有一个方法可以创建2个不同的待处理意图来启动2个警报。此方法在完成时调用广播方法,但是根据它接收的意图我需要执行不同的操作
提前感谢,
安迪
提示课
public void setSleepPrompts(Context context){
try{
Intent intent = new Intent(context, SleepPromptReceiver.class );
PendingIntent firstSender = PendingIntent.getBroadcast(context, 1, intent, 0);
PendingIntent secondSender = PendingIntent.getBroadcast(context, 2, intent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, (this.getBedTimeEpoch() - this.firstPromptOffset), firstSender);
am.set(AlarmManager.RTC_WAKEUP, (this.getBedTimeEpoch() - this.secondPromptOffset), secondSender);
} catch (Exception e){
Log.i(TAG, e.toString());
}
}
广播接收器类
@Override
public void onReceive(Context context, Intent intent) {
try{
if(intent.GET_THE_INTENT_ID?)
Toast.makeText(context, "kapow chow", Toast.LENGTH_SHORT).show();
} catch (Exception e){
Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
}
}
答案 0 :(得分:1)
创建意图时使用intent.putExtra("id", "intent x")
,然后
if(intent.getStringExtra("id").equals("intent x"))
Toast.makeText(context, "kapow chow", Toast.LENGTH_SHORT).show();