为什么我的BroacastReceiver不起作用?

时间:2014-06-07 20:33:39

标签: android broadcastreceiver

请告诉我,我做错了什么?

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>

1 个答案:

答案 0 :(得分:2)

请务必在清单中设置正确的权限。