如何在android中报警时从挂起的意图中获取requestCode

时间:2012-11-27 14:17:46

标签: android android-intent alarmmanager alarm android-pendingintent

是否可以在Receiver类或Activity Class中获取requestCode?

这是我未决的意图

alarmMgr= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                Intent intent = new Intent(this, BroadcastReceiver_Class.class);
                /*intent.putExtra("alarm_time_minutes", minutes);*/
                pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent,requestCode);
                alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

先谢谢..

1 个答案:

答案 0 :(得分:9)

您可以将requestCode作为额外的意图。如下:

intent.putExtra("requestCode", requestCode);

然后你可以通过以下方式在Activity类中获取它:

int requestCode = received_intent.getExtras().getInt("requestCode");