Android 5.0.1 を実行している Nexus 9 に Bluetooth ヘッドセット デバイスを接続しています。
私のアプリは次のコードを実行しており、getA2dpConnectedDevice() を呼び出して A2DP の状態を確認しています。アプリデバイスはヘッドセットに接続されていると思われるため、 BluetoothProfile.ServiceListener().onServiceConnected が起動することを期待していますが、起動しません。
private void getA2dpConnectedDevice() {
// Establish connection to the proxy.
mBluetoothAdapter.getProfileProxy(this, mA2dpProfileListener,
BluetoothProfile.A2DP);
logAndPostMessage( "Requesting A2DP connection status");
}
private BluetoothProfile.ServiceListener mA2dpProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.A2DP) {
mBluetoothA2dp = (BluetoothA2dp) proxy;
ArrayList<BluetoothDevice> a2DPdevices = (ArrayList) mBluetoothA2dp
.getDevicesMatchingConnectionStates(new int[] { BluetoothA2dp.STATE_CONNECTED });
// if any connected devices, should only be one
if (a2DPdevices.size() > 0) {
addDeviceToDeviceMap(a2DPdevices.get(0), null);
// post connected msg
logAndPostMessage( "A2DP is connected. Fired A2DPStatusUpdate event");
post(new A2DPStatusUpdate(a2DPdevices.get(0),
BluetoothA2dp.STATE_CONNECTED));
getHeadsetConnectedDevice();
}
}
}
上記のコードが機能するはずであるという私の考えに問題はありますか?
奇妙なことに (Android に問題がある本当の手がかりかもしれません)、ステータス バーの Bluetooth アイコンはヘッドセットが接続されていることを示していますが、Bluetooth 設定画面に移動すると、ヘッドセットがまったく表示されません。
知恵の言葉をいただければ幸いです。