2011-09-13 28 views
1

當電話狀態從振鈴轉爲空閒時,我需要調用一個活動。但它說構造函數Intent(MyPhoneStateListener,Class)未定義。如何調用活動。需要調用PhoneStateListener中的活動

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; 
       } 
       } 
    } 

回答

1

,你可以這樣調用的活動:

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

謝謝Vineet。但它說「方法startActivity(Intent)未定義類型MyPhoneStateListener」。 – Manikandan

+0

將MyPhoneStateListener類放入服務中...選中此項:http://lovingandroid.blogspot.com/2011/07/intercept-call-activity.html –

+0

儘管我將MyPhoneStateListener類放入服務中,但我得到了同樣的錯誤。 – Manikandan

0

我有同樣的問題(如Manikandan),Eclipse的告訴我說:「該方法startActivity(意向)是未定義的類型MyPhoneStateListener「是否可以用其他方式觸發一個意圖?

+0

This Works ...... Intent missintent = new Intent(context,MissedCall.class); missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(missintent); – Manikandan

0

請注意,您的MyPhoneStateListener類必須在Activity類中定義,否則不存在啓動活動的上下文。

相關問題