简体   繁体   English

检测服务内的来电

[英]Detect incoming calls inside a service

Inside a service I have: 在服务内部,我有:

// subscribe to incoming call notifications
registerReceiver(mIncomingCallReceiver, new IntentFilter("android.intent.action.PHONE_STATE"));

However onReceive never gets called: 但是onReceive永远不会被调用:

// incoming call receiver
private BroadcastReceiver mIncomingCallReceiver = new BroadcastReceiver() {
   @Override
   public void onReceive(Context context, Intent intent) {

What's wrong here? 怎么了 I don't want to declare it through the manifest and additional class since it would require additional code to invoke corresponding method inside my service. 我不想通过清单和其他类声明它,因为它将需要其他代码来调用服务中的相应方法。

PS What I need to do is to stop the service player when an incoming call is registered. PS我需要做的是在注册到来电时停止服务播放器。

也许你的清单错过了

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM