I have a question about opening and closing bluetoothdevices and mididevices.
I've made an app with which you can practise playing notes. The app checks if the note played on the piano is the same note as displayed in the app. The app reuses the code from the MidiBtlePairing example.
Connecting to the piano (Roland FP30) with bluetooth however is troublesome:
- only the first time connecting succeeds (clean situation, after resetting the phone);
The app is connected to the piano (bluetooth light is lit up), the piano BTLE stops advertising because it's connected.
If I open an output ports data is sent from piano to app. The app works as expected.
- after closing this first connection, almost all attempts to reconnect thereafter fail;
opening the bluetoothdevice with MidiManager.openBluetoothDevice() is directly followed by a MidiManager.DeviceCallback.onDeviceRemoved (which is not initiated by calling Closeable.close() from the app).
The device ID in MidiDeviceInfo is increased, so it seems the device is opened (MidiService.addDeviceLocked, mNextDeviceId++) but it immediately is closed after opening.
Could it be possible that the close is initiated by the MidiService? If yes, why?
- sometimes, after closing the first connection, reconnecting with MidiManager.openBluetoothDevice() opens a mididevice without establishing a connection.
The bluetooth light on the piano is not lit up, the piano BTLE is still advertising.
I can open an output port on the mididevice but no data is exchanged.
If I close the app after 5 or 6 unsuccessfull connection attempts and reopen the app, the phone usually reboots after the first call to MidiManager.openBluetoothDevice().
I see this behaviour discussed in other posts on this forum (for instance BluetoothDevice and MidiDevice, 14-01-2019).
It looks like the mididevice (or bluetoothdevice) is not properly closed or properly administrated (in my app or in the MidiService?).
What could possibly cause this behaviour?
Any help here would be appreciated.
Thanks in advance.