當電話狀態從鈴聲變成空閒時,我需要調用一個activity。我用的下面的代碼調用了這個activity。
但是錯誤提示: The constructor Intent(MyPhoneStateListener, Class) is undefined.
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;
}
}
}
如何調用呢?
Intent missintent=new Intent(this,MissedCall.class);
你這裡的this指的是當前的activity? 目前應該是MyPhoneStateListener 這個類的吧
換成當前activity.this
試下