I have the following code:
String state= bundle.getString(TelephonyManager.EXTRA_STATE);
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_INCOMING_NUMBER)
{
Toast toast= new Toast(context);
toast.setGravity(Gravity.TOP,0,0);
toast.setDuration(Toast.Length_LONG);
toast.makeText(..).show();
toast.show();
}
I need to keep the toast up until the person answers to the phone. How to do that? I know I have to create and start a thread when I have incoming number and stop the thread when the person answers. how to accomplish this?
thx
Try like this..
Toast.Length_LONG gives toast for only 3.5 seconds..
so.. create a countdowntimer of 3.5 seconds like this..in your activity's onCreate
String state= bundle.getString(TelephonyManager.EXTRA_STATE);
MyCount counter;
counter=new MyCount(3500,1000);
counter.start();
MyCount class..
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_INCOMING_NUMBER){
Toast toast= new Toast(youractivity.this);
toast.setGravity(Gravity.TOP,0,0);
toast.setDuration(Toast.Length_LONG);
toast.makeText(..).show();
toast.show();
counter= new MyCount(3500,1000);
counter.start();
}
}
@Override
public void onTick(long millisUntilFinished) {
}
}
}
this continuously shows toast till you answer the call..or your incoming call ends due to timeout..