gpt4 book ai didi

android - 显示可视化组件而不引用 Context

转载 作者:行者123 更新时间:2023-11-30 03:13:05 24 4
gpt4 key购买 nike

我有自己的 PhoneStateListener 实现

public class PhoneCallListener extends PhoneStateListener {

private Context context;

public PhoneCallListener(Context context)
{
super();
this.context = context;
}

@Override
public void onCallStateChanged(int state, String incomingNumber) {

if(state == TelephonyManager.CALL_STATE_RINGING)
Log.i("PHONE_CALL", "Number: " + incomingNumber);

Toast.makeText(context.getApplicationContext(), "Somebody is calling!", Toast.LENGTH_LONG);
}
}

我想显示任何视觉组件,即。在上面的代码中 toast 。但我不知道为什么它不显示任何内容。可能上下文有问题,但它不会写任何错误。在 LogCat 中有正确写入的传入号码,一切看起来都正确,但 Toast 不会随时显示..

最佳答案

你没有把 .show() 放在 toast 上让它实际显示

像这样

Toast.makeText(context.getApplicationContext(), "Somebody is calling!", Toast.LENGTH_LONG).show();

关于android - 显示可视化组件而不引用 Context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20601373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com