我正试图在服务中捕获传出呼叫,现在我希望调试器控制台中有一些东西。
我创建了一个DailerReceiver
(在清单中添加了谁并扩展了BroadcastReceiver
)。然后我添加IntentFilter
android.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 #####################
答案 0 :(得分:3)
您尝试在服务中注册广播接收器的任何原因。而且 - 您是否从您的活动中调用startService()?如果是这样 - 你不需要
<intent-filer>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filer>
在清单中提供服务。我刚刚用你的代码创建了一个示例应用程序,不包括服务的intent-filter,而且我的onRecieve运行正常。
答案 1 :(得分:1)
您不需要添加此
<intent-filer>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filer>
清单中的因为您正在服务中注册接收者onCreate()。
由于同样的原因,你也不需要在清单中注册接收器。
检查您是否在清单中添加了 android.permission.PROCESS_OUTGOING_CALLS 权限。
尝试替代方法:检查this。