开发者

Need to call a activity in PhoneStateListener

开发者 https://www.devze.com 2023-04-05 00:35 出处:网络
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.

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开发者_JAVA技巧_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;
                }
              }
    }


you can call the activity like this:

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


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 ?


Note that your MyPhoneStateListener class must be defined within an Activity class, otherwise there is no context from which to launch an activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号