需要调用PhoneStateListener中的一个activity
当电话状态从响铃变为空闲时,我需要调用一个活动。但它说构造函数 Intent(MyPhoneStateListener, Class) 未定义。如何调用活动。
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;
}
}
}
I need to call a activity when the phone state comes from ringing to idle. But It says The constructor Intent(MyPhoneStateListener, Class) is undefined. How can call the 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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样调用该活动:
you can call the activity like this:
我遇到了同样的问题(如 Manikandan),Eclipse 告诉我“MyPhoneStateListener 类型的方法 startActivity(Intent) 未定义”是否可以以其他方式触发意图?
I've got the same problem (as Manikandan), Eclipse tell me that "The method startActivity(Intent) is undefined for the type MyPhoneStateListener" is it possible to fire an intent in an other way ?
请注意,您的 MyPhoneStateListener 类必须在 Activity 类中定义,否则将没有上下文可用于启动活动。
Note that your MyPhoneStateListener class must be defined within an Activity class, otherwise there is no context from which to launch an activity.