2

着信時に 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);
            }
4

1 に答える 1

0

私の知る限り、startActivityForResult() メソッドを呼び出せるようにするには、クラスで Activity クラスを拡張する必要があります。これが役立つことを願っています。

于 2013-07-10T01:42:54.720 に答える