当电话状态从铃声变成空闲时,我需要调用一个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
试下
new Intent("some.string");
AndroidManifest.xml里,把你对应的Activity加个IntentFilter,跟这个intent联系起来。
这样调用 activity :
Intent missintent= new Intent(context, MissedCall.class);
missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(missintent);