Wednesday, April 18, 2012

toast message android

I am trying to pop up a toast message as long as the phone rings and destroy the toast them the call is rejected or answered.



In the OnReceive method I have something like this:



Bundle bundle=intent.getExtras();
final String state=bundle.getString(TelephonyManager.EXTRA_STATE);

if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
Toast toast= new Toast(context);
toast.show();

new CountDownTimer(3500,1000)
{

@Override
public void onFinish()
{
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)||
(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
toast.cancel();
}
else
{
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
start();
}
}


The problem is that even after the call is hanged up the toast message keeps poping up. It's like the state is never in the HANG_UP or IDLE Mode.



What did I do wrong?





No comments:

Post a Comment