0

我有以下代码:

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();
}

我需要继续敬酒,直到对方接电话。怎么做?我知道我必须在收到号码时创建并启动一个线程,并在对方回答时停止该线程。如何做到这一点?

谢谢

4

1 回答 1

0

试试这样。。

 Toast.Length_LONG gives toast for only 3.5 seconds..

所以..像这样创建一个 3.5 秒的倒数计时器..在你的活动的 onCreate

 String state= bundle.getString(TelephonyManager.EXTRA_STATE);
 MyCount counter;
counter=new MyCount(3500,1000);
counter.start();

MyCount 类..

   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) {
    }
}
}

这会持续显示敬酒,直到您接听电话..或您的来电因超时而结束..

于 2012-04-10T15:53:21.483 回答