How to get requestCode from pending intent at the time of alarm in android

Vishnu picture Vishnu · Nov 27, 2012 · Viewed 7.5k times · Source

Is it possible to get requestCode at the time of intent either in Receiver class or Activity Class?

and this was my pending Intent

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);

Thanks in Advance..

Answer

Kerim Oguzcan Yenidunya picture Kerim Oguzcan Yenidunya · Nov 27, 2012

You can put requestCodeas extra to your intent. Like following:

intent.putExtra("requestCode", requestCode);

Then you can get it in Activity class by:

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