请告诉我,我做错了什么?
BroacastReceiver
应该收听来电和拨打电话。
这是接收者:
public class CallReceiver extends PhonecallReceiver {
@Override
protected void onIncomingCallStarted(String number, Date start) {
Log.e("CyranoActivty","disableBluetooth");
BluetoothManager.stopBluetooth();
}
@Override
protected void onOutgoingCallStarted(String number, Date start) {
Log.e("CyranoActivty","disableBluetooth");
BluetoothManager.stopBluetooth();
}
@Override
protected void onIncomingCallEnded(String number, Date start, Date end) {
Log.e("CyranoActivty","enableBluetooth");
BluetoothManager.restartBluetooth();
}
@Override
protected void onOutgoingCallEnded(String number, Date start, Date end) {
Log.e("CyranoActivty","enableBluetooth");
BluetoothManager.restartBluetooth();
}
@Override
protected void onMissedCall(String number, Date start) {
}
}
here link to the superclass of CallReceiver
接收者已在活动的onCreate()
中注册
phonecallreceiver = new CallReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.PHONE_STATE");
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
registerReceiver(phonecallreceiver, filter);
这是我的清单:
<activity
android:name="com.cjcornell.samplebluetooth.CyranoActivity"
android:label="@string/title_activity_cyrano" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</activity>
答案 0 :(得分:2)
请务必在清单中设置正确的权限。