2

私はAndroid2.2APIレベル8用にプログラミングしており、アプリケーションの起動時に現在Bluetoothヘッドセットが接続されているかどうかを調べようとしています。この問題の解決策が見つからないようです。

アプリケーションが起動して実行されると、ここに示されているように、BluetoothDevice.ACTION_ACL_CONNECTEDとBluetoothDevice.ACTION_ACL_DISCONNECTEDをリッスンできます。しかし、BroadcastReceiverがオンになる前に、現在Bluetoothヘッドセットが接続されているかどうかを確認する方法がわかりません。

また、次の方法で、デバイスにペアリングされたデバイスがあるかどうかを確認する方法もわかりました。

BluetoothAdapter mBluetoothAdapter = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter != null)
{
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() != 0)
    {
        // the device has paired devices
        for (BluetoothDevice device : pairedDevices)
        {
            Log.i(TAG, "device name: " + device.getName());
            Log.i(TAG, "device address: " + device.getAddress());
        }
    }
    else
    {
        // no paired devices
        Log.i(TAG, "no paired devices");
    }
}

誰かがAPIレベル8のこの問題の解決策をすでに持っていることを望んでいます。API11には、 おそらく1行のコードでこれを実行できるBluetoothProfileBluetoothHeadsetなどの新しいクラスがあることを認識しています。 APIレベル8でこれを行おうとしています

私はこの時点で何でも試してみるつもりです。

前もって感謝します

-H

4

2 に答える 2

4

次のコードは私にとってはうまくいきます。まず、BT デバイスを Android に手動で接続します。

AudioManager am = getSystemService(Context.AUDIO_SERVICE)
if( am.isBluetoothA2dpOn() )
{
    //bt device is connected with phone
}
else{
   // no device is connected with phone
}
于 2014-05-22T10:34:45.670 に答える