How can I choose an incoming call in Android?

I am developing an Android application and want to know how I can receive an incoming call. I created a broadcast receiver and in my receiving method I gave a 15 second delay using the countdown timer when making a call in call mode. Now I want to receive an incoming call in the method of completing the countdown timer. I get no way to implement it. can anyone suggest? thank!!

+3
source share
2 answers

instead of using a countdown timer, set a one-time Alarm, and then run 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);
+2
source

, coundowntimer 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();

countdowntimer http://www.filefactory.com/file/cbbbc38/n/SimpleCountDownTimerExample.zip

+1

All Articles