6

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..

Vishnu
  • 349
  • 3
  • 8
  • 16

1 Answers1

10

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");  
  • but how come built-in android apps such as camera and gallery knows the request code that you pass? @Kerim – what is sleep Nov 11 '13 at 20:38
  • 1
    Why this approach works, it doesn't make any sense. The requestCode parameter would become redundant in the method `PendingIntent.getBroadcast()` – ericn Jul 08 '14 at 01:24
  • actually the requestCode in PendingIntent.getBroadcast() makes sense and give you a new pending intent – memical Aug 07 '14 at 18:52