我正在尝试制作一个在来电中显示吐司的应用程序,并在拒绝decall或停止振铃但无法正常工作时销毁该吐司!我的代码是:
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
LayoutInflater mInflater = LayoutInflater.from(context);
View myView = mInflater.inflate(R.layout.toast, null);
ImageView image = myView.findViewById(R.id.image);
image.setImageResource(R.drawable.thumb);
TextView text = (TextView) myView.findViewById(R.id.text);
text.setText("prueba");
toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(myView);
toast.show();
timer = new CountDownTimer(9000, 1000)
{
public void onTick(long millisUntilFinished) {toast.show();}
public void onFinish() {toast.show();}
}.start();
toast.cancel();
}
}
if ((state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))) {
//Toast.makeText(context,"Call Received State",Toast.LENGTH_SHORT).show();
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
toast.cancel();
timer.cancel();
}
当状态更改为TelephonyManager.EXTRA_STATE_IDLE时,我想销毁TelephonyManager.EXTRA_STATE_RINGING中显示的烤面包
问题是:做得好!除了当状态更改为TelephonyManager.EXTRA_STATE_IDLE时,吐司仍然在屏幕上,无法取消!
请帮助!