4

Android 4.3 で Bluetooth デバイスに接続する必要があるアプリケーションを開発しています。

getConnectedDevices()そして、 by を使用して BLE デバイスを接続した後、接続されたデバイスを取得するために次のコードのように使用したいのですがmBluetoothGatt.connect()、機能していません。

    @Override
    public void onServiceDisconnected(int profile) {
        // TODO Auto-generated method stub
        Log.v(TAG, "profile1" + profile);
        Log.v(TAG, "BluetoothProfile.HEADSET1 = " + BluetoothProfile.HEADSET);
        if(profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset  = null;
        }
    }

    @Override
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        // TODO Auto-generated method stub
        Log.v(TAG, "profile2 " + profile);
        Log.v(TAG, "BluetoothProfile.HEADSET2 = " + BluetoothProfile.HEADSET);
        if(profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset  = (BluetoothHeadset) proxy;

            Log.v(TAG, "mBluetoothHeadset = " + mBluetoothHeadset);
            List<BluetoothDevice> devicelist = mBluetoothHeadset.getConnectedDevices();
            Log.v(TAG, "mBluetoothHeadset.getConnectedDevices = " + mBluetoothHeadset.getConnectedDevices());
            Log.v(TAG, "devicelist = " + devicelist);
            for(BluetoothDevice dev : devicelist) {
                Log.v(TAG, "connectedDevices = " + dev);
            }
        }
    }
    };



@Override
    protected void onNewIntent(Intent intent) {
        // TODO Auto-generated method stub
        super.onNewIntent(intent);
        setIntent(intent);

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mBluetoothAdapter.getProfileProxy(Main.this, mProfileListener, BluetoothProfile.HEADSET);




}

ログから見ると、関数 getConnectedDevices(); は呼び出されませんでした。ログは次のとおりです。

D/BluetoothHeadset( 3454): Proxy object connected
V/Main    ( 3454): profile2 = 1
V/Main    ( 3454): BluetoothProfile.HEADSET2 = 1
V/Main    ( 3454): mBluetoothHeadset = android.bluetooth.BluetoothHeadset@4a99cddc
V/Main    ( 3454): mBluetoothHeadset.getConnectedDevices = []
V/Main    ( 3454): devicelist = []

接続済みのリストは空です。接続されている BLE デバイスが 1 つあるはずです。私のコードに何か問題がありますか??

4

0 に答える 0