我正在尝试接听电话时启用蓝牙。我已使代码使用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);
}
答案 0 :(得分:0)
我的知识是你的类需要扩展Activity类才能调用startActivityForResult()方法。希望这会有所帮助。