2011-05-07 18 views
0

因此,我有一個服務在後臺運行(這是超級祕密,所以我不能告訴你它是什麼:)),但我需要當用戶發起呼叫或者呼叫進入時能夠關閉它。到目前爲止,我已經檢查了Intent.ACTION_ANSWER,但是由於某種原因,我的廣播接收機從未檢測到它。我也嘗試過使用PhoneStateListener,但在我的案例中,我無法理解如何使用我的服務做任何事情。 PhoneStateListener是什麼情況?當呼叫進入和用戶撥打號碼時需要關閉服務

一些示例代碼爲我BroadcastReceiver

public void onReceive(Context context, Intent intent) {  
if (intent.getAction().equals(Intent.ACTION_ANSWER)) { 
     phoneRinging = true;    
    } 

Intent i = new Intent(context, MyService.class);   
    i.putExtra("phone", phoneRinging); 
    context.startService(i); 
} 

這裏是通過PhoneStateListener啓動服務的一個片段。 例子:startService(new Intent(---CONTEXT---, MySuperSecretService.class))

和接收器是在清單:

<receiver android:name=".PhoneReceiver" android:enabled="true"> 
    <intent-filter> 
     <action android:name="android.intent.action.ANSWER"></action> 
    </intent-filter> 
</receiver> 

WTH進入CONTEXT部分在此聲明,如果我在PhoneStateListener

回答

相關問題