2011-05-07 75 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

回答

相关问题