[英]toast message android
只要电话响起,我就会尝试弹出一条祝酒词,并销毁祝酒词,拒绝或接听电话。
在OnReceive
方法中,我有如下内容:
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();
}
}
问题是即使挂断了电话,吐司消息仍然不断弹出。 就像状态永远不会处于HANG_UP或IDLE模式一样。
我做错了什么?
在您广泛的接受者中使用此
@Override
public void onReceive(Context context, Intent intent) {
Log.d("INCOMING", "service start");
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
// telephonyService = (ITelephony) m.invoke(tm);
Bundle bundle = intent.getExtras();
String phoneNumber = bundle.getString("incoming_number");
Log.d("INCOMING", phoneNumber);
if ((phoneNumber != null) && !phoneNumber.equals(selectedtednumber)) {
Toast.makeText(context, "Someone other calling sending to voice mail ...", Toast.LENGTH_LONG).show();
sendToVoiceMail();
}
}
这是Toast功能的错误使用。 您应该找到另一种方法来做您想做的事。
我认为最符合您需求的是PopupWindow 。 查看文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.