Мое приложение обратного отсчета использует текст в речь для обеспечения обратного отсчета звука. < /p>
Когда приложение обнаруживает звук Bluetooth-динамика, отправляется на этот динамик. Мой оригинал Oncreate () включен: < /p>
// Check if a speaker is connected
if (bluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED)
sendSpeechToSpeaker()
else
sendSpeechToPhone()
< /code>
Вопрос 1 < /strong>
Есть ли простое исправление к приведенным выше, которое будет обнаружить только подключенные гарнитуры? Обходной путь?val btServiceListener: ServiceListener = object : ServiceListener {
// used to scan all CONNECTED Bluetooth devices looking for external speakers ...
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
if (profile == BluetoothProfile.HEADSET) {
val connectionStates = intArrayOf(BluetoothProfile.STATE_CONNECTED)
// get all connected headsets
val connectedHeadsetList = proxy.getDevicesMatchingConnectionStates(connectionStates)
for (connectedHeadset in connectedHeadsetList) {
// check each headset and check if it is ACTUALLY a headset
val majorMask = BluetoothClass.Device.Major.UNCATEGORIZED // actually want to use BITMASK but some Fwit declared it private !
val isHeadset = (connectedHeadset.bluetoothClass?.deviceClass?.and(majorMask) == BluetoothClass.Device.Major.AUDIO_VIDEO)
if (isHeadset)
sendSpeechToSpeaker()
}
}
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, proxy) // here we are finished with the proxy so clear
}
override fun onServiceDisconnected(profile: Int) {}
}
< /code>
Приведенный выше слушатель вызывается in create () < /p>
// search the list of connected bluetooth headsets
bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
bluetoothAdapter = bluetoothManager.adapter
bluetoothAdapter.getProfileProxy(this, btServiceListener, BluetoothProfile.HEADSET);
< /code>
Слушатель работает, используя основную маску
Код для гарнитур - (0x0400)
Samsung Galaxy Wath Отсоединяет, он не направляет звук от динамика!
Подробнее здесь: https://stackoverflow.com/questions/727 ... h-headsets
Android: носить часы, о которых сообщалось как подключенные гарнитуры Bluetooth? ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как обнаружить отключение Bluetooth-гарнитуры в веб-приложении Chrome для Android?
Anonymous » » в форуме Android - 0 Ответы
- 13 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как получать события воспроизведения/паузы Bluetooth-гарнитуры при TextToSpeech.speak()?
Anonymous » » в форуме Android - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-
-
-
АНДРОИД: Можно ли с помощью Bluetooth-гарнитуры разговаривать как по рации?
Anonymous » » в форуме Android - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-