着信時に Bluetooth を有効にしようとしています。を使用して着信を検出するコードを作成しましたcallstatelistener
。ただし、同じリスナーから Bluetooth アクティベーションをトリガーすることはできません。次のコードを試しましたが、コンパイル エラーが発生し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);
}