Shrey
Shrey

Reputation: 238

how can I pick an incoming call in android?

I am developing an android app and want to know how can I receive an incoming call. I have created a broadcast receiver and in its on receive method I have given a 15 second delay using countdown timer on call state ringing.Now, I want to receive an incoming call in countdown timer's finish method. I am not getting any way to implement it. can anyone suggest ? thanks!!

Upvotes: 3

Views: 183

Answers (2)

Jitesh Upadhyay
Jitesh Upadhyay

Reputation: 5260

hi you can use a coundowntimer visit http://developer.android.com/reference/android/os/CountDownTimer.html

new CountDownTimer(15000, 1000) {

 public void onTick(long millisUntilFinished) {

  //here you can have your logic for call
 }

 public void onFinish() {
     mTextField.setText("done!");
 }
}
.start();

for working code example of countdowntimer visit http://www.filefactory.com/file/cbbbc38/n/SimpleCountDownTimerExample.zip

Upvotes: 1

ardevd
ardevd

Reputation: 3407

instead of using a countdown timer, set a one-time Alarm instead which then fires your method to receive the call. You can do something like this:

AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent cHandler = new Intent (this, CallHandlers.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, cHandler, PendingIntent.FLAG_CANCEL_CURRENT);
//Set an alarm that will trigger in 15 seconds
alarm.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (15 * 1000), pi);

Upvotes: 2

Related Questions