2

我正在尝试在服务中捕获拨出电话,现在我希望调试器控制台中有一些东西。

我创建了一个DailerReceiver(在清单中添加并扩展了BroadcastReceiver)。然后我添加一个IntentFilterandroid.intent.action.NEW_OUT_GOING_CALL注册接收器。我还在清单中启用了该服务。我希望这些是必需的步骤。

清单中还有更多信息。我不确定这是否真的有必要,但在示例中添加了它以获得整个画面。

服务部分:

public class BackgroundService extends Service {

    @Override
    public void onCreate() {
        DialerReceiver mReceiver = new DialerReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
        this.registerReceiver(mReceiver, filter);
    }
}

DialerReceiver

public class DialerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        debugOut("arg0: " + arg0.toString());
        debugOut("arg1: " + arg1.toString());
        debugOut("isOrderedBroadcast = " + isOrderedBroadcast());
    }

    private static void debugOut(String str) {
        Log.d("DialerReceiver", str);
    }
}

清单的一部分:

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

<receiver 
    android:name=".DialerReceiver"
    android:enabled="true">
    <intent-filter android:priority="2147483647">
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter>
</receiver>

<service
    android:name=".BackgroundService"
    android:enabled="true">            
    <intent-filer>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>                
    </intent-filer>
</service>

从发生测试呼叫的那一刻起的完整错误日志:

03-14 09:28:32.095: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState0
03-14 09:28:32.095: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState0
03-14 09:28:32.140: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState0
03-14 09:28:32.140: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState0
03-14 09:28:32.370: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState36
03-14 09:28:32.370: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState36
03-14 09:28:32.420: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState32
03-14 09:28:32.420: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState32
03-14 09:28:32.880: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState779
03-14 09:28:32.880: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState779
03-14 09:28:33.065: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState779
03-14 09:28:33.065: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState779
03-14 09:28:33.730: E/SpannableStringBuilder(31997): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-14 09:28:33.730: E/SpannableStringBuilder(31997): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-14 09:28:35.195: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState5
03-14 09:28:35.195: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState5
03-14 09:28:35.300: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState154
03-14 09:28:35.300: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState154
03-14 09:28:35.405: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState154
03-14 09:28:35.405: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState154
03-14 09:28:35.530: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState154
03-14 09:28:35.530: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState154
03-14 09:28:35.620: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState37
03-14 09:28:35.620: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState37
03-14 09:28:35.765: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState37
03-14 09:28:35.765: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState37
03-14 09:28:35.850: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState7
03-14 09:28:35.855: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState7
03-14 09:28:35.995: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState7
03-14 09:28:35.995: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState7
03-14 09:28:36.050: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState7
03-14 09:28:36.050: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState7
03-14 09:28:37.735: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState5
03-14 09:28:37.735: E/TwAdapterView(31997): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState5
03-14 09:28:37.775: E/SpannableStringBuilder(31997): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-14 09:28:37.775: E/SpannableStringBuilder(31997): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-14 09:28:39.155: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=DIALING, mBCall=IDLE, mRCall=IDLE, mCallsetup=0, mCall=0, mCallheld=0
03-14 09:28:39.155: E/Bluetooth HS/HF(2853): audioOn()
03-14 09:28:39.155: E/Bluetooth HS/HF(2853): audioOn(): headset is not connected!
03-14 09:28:39.170: E/TinyUCM(1921): There aren't inputs in map or set stereo(0)
03-14 09:28:39.170: E/TinyUCM(1921): Stereo is already enabled
03-14 09:28:39.170: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:39.205: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=DIALING, mBCall=IDLE, mRCall=IDLE, mCallsetup=2, mCall=0, mCallheld=0
03-14 09:28:39.205: E/Bluetooth HS/HF(2853): audioOn()
03-14 09:28:39.205: E/Bluetooth HS/HF(2853): audioOn(): headset is not connected!
03-14 09:28:39.390: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=DIALING, mBCall=IDLE, mRCall=IDLE, mCallsetup=2, mCall=0, mCallheld=0
03-14 09:28:39.390: E/Bluetooth HS/HF(2853): audioOn()
03-14 09:28:39.390: E/Bluetooth HS/HF(2853): audioOn(): headset is not connected!
03-14 09:28:39.435: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=DIALING, mBCall=IDLE, mRCall=IDLE, mCallsetup=2, mCall=0, mCallheld=0
03-14 09:28:39.435: E/Bluetooth HS/HF(2853): audioOn()
03-14 09:28:39.435: E/Bluetooth HS/HF(2853): audioOn(): headset is not connected!
03-14 09:28:41.820: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:42.920: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=ALERTING, mBCall=IDLE, mRCall=IDLE, mCallsetup=2, mCall=0, mCallheld=0
03-14 09:28:44.300: E/TinyUCM(1921): There aren't inputs in map or set stereo(2100000)
03-14 09:28:44.300: E/TinyUCM(1921): Stereo is already enabled
03-14 09:28:44.300: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:45.205: E/Watchdog(2277): !@Sync 1113
03-14 09:28:46.555: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=ACTIVE, mBCall=IDLE, mRCall=IDLE, mCallsetup=3, mCall=0, mCallheld=0
03-14 09:28:46.555: E/Bluetooth HS/HF(2853): audioOn()
03-14 09:28:46.555: E/Bluetooth HS/HF(2853): audioOn(): headset is not connected!
03-14 09:28:50.105: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=OFFHOOK, mFCall=DISCONNECTING, mBCall=IDLE, mRCall=IDLE, mCallsetup=0, mCall=1, mCallheld=0
03-14 09:28:50.555: E/Bluetooth HS/HF(2853): audioOff(): mPendingScoForA2dp: false, mPendingScoForWbs: false, mConnectedSco: null, mA2dpState: 11, mA2dpSuspended: false, mVoiceRecognitionStarted: false
03-14 09:28:50.605: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:50.605: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:50.605: E/TinyUCM(1921): Builtin Mic: active count 1
03-14 09:28:50.605: E/TinyUCM(1921): Back Mic: active count 1
03-14 09:28:50.605: E/TinyUCM(1921): modifier doesn't exists any more
03-14 09:28:50.840: E/ActivityThread(2853): Failed to find provider info for com.cequint.ecid
03-14 09:28:55.470: E/BargeInRecognizer(2853): stopBargeIn
03-14 09:28:55.515: E/Bluetooth HS/HF(2853): handlePreciseCallStateChange() mPhone=IDLE, mFCall=IDLE, mBCall=IDLE, mRCall=IDLE, mCallsetup=0, mCall=0, mCallheld=0
03-14 09:28:55.515: E/Bluetooth HS/HF(2853): audioOff(): mPendingScoForA2dp: false, mPendingScoForWbs: false, mConnectedSco: null, mA2dpState: 11, mA2dpSuspended: false, mVoiceRecognitionStarted: false
03-14 09:28:55.900: E/WifiP2pStateTracker(2277): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
03-14 09:28:58.175: E/WifiHW(2277): ##################### set firmware type 0 #####################
03-14 09:28:58.385: E/WifiHW(2277): ##################### set firmware type 0 #####################
4

2 回答 2

3

您尝试在服务中注册广播接收器的任何原因。而且 - 你是从你的活动中调用 startService() 吗?如果是这样 - 你不需要

<intent-filer>
    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>                
</intent-filer>

在服务清单中。我刚刚使用您的代码创建了一个示例应用程序,不包括服务的意图过滤器,并且我的 onRecieve 工作正常。

于 2013-03-14T09:13:24.080 回答
1

你不需要添加这个

    <intent-filer>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>                
    </intent-filer>

在清单中。因为您正在服务的 onCreate() 中注册接收器。

由于同样的原因,您也不需要在清单中注册接收者。

检查您是否在清单中添加了android.permission.PROCESS_OUTGOING_CALLS权限。

尝试替代方法:检查一下

于 2013-03-14T08:09:58.093 回答