2

我正在尝试在接到电话时启用蓝牙。我已经编写了代码来使用callstatelistener. 但是,我无法从同一个侦听器触发蓝牙激活。我尝试了以下代码,但它给了我一个编译错误The method startActivityForResult(Intent, int) is undefined for the type CallHelper.CallStateListener。你们中的任何人都可以帮我吗?

final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
/**
 * Listener to detect incoming calls. 
 */

private class CallStateListener extends PhoneStateListener {
    private static final int REQUEST_ENABLE_BT = 0;
    public boolean wasRinging;
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
            // called when someone is ringing to this phone


            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, 0);
            }
4

1 回答 1

0

我的知识是您的类需要扩展 Activity 类才能调用 startActivityForResult() 方法。希望这会有所帮助。

于 2013-07-10T01:42:54.720 回答