0
我正在處理2個單獨的警報。我有一個方法在我的班級創建2個不同的意圖啓動2個警報。此方法調用然而,當完全取決於其意圖接收我需要執行不同的操作Android - 具有待定意圖的多個警報,如何確定正在調用哪個意圖?
提前感謝廣播方式,
安迪
提示類
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();
}
}
感謝這麼快:)我在想,如果你可以使用意圖ID,但我可能會使用它代替 – Garbit