gpt4 book ai didi

android - 需要在 PhoneStateListener 中调用一个 Activity

转载 作者:行者123 更新时间:2023-11-30 04:32:47 25 4
gpt4 key购买 nike

我需要在电话状态从响铃变为空闲时调用一个 Activity 。但它说 构造函数 Intent(MyPhoneStateListener, Class) 未定义。如何调用 Activity 。

    public class MyPhoneStateListener extends PhoneStateListener {
//static String org="";

public void onCallStateChanged(int state,String incomingNumber){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
Log.d("DEBUG", "IDLE");
// MissedCall ms=new MissedCall();

Intent missintent=new Intent(this,MissedCall.class);
startActivity(missintent);

break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("DEBUG", "OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("DEBUG", "RINGING");
break;
}
}
}

最佳答案

您可以这样调用 Activity :

Intent missintent= new Intent(context, MissedCall.class);
missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(missintent);

关于android - 需要在 PhoneStateListener 中调用一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400338/

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