mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Ensured that gatt connection priority is only requested after the gatt has connected
This commit is contained in:
parent
308f634f62
commit
3cd9bed7d9
2 changed files with 62 additions and 16 deletions
|
|
@ -491,12 +491,20 @@ public class MidiTest extends Activity
|
|||
//==============================================================================
|
||||
private class DummyBluetoothGattCallback extends BluetoothGattCallback
|
||||
{
|
||||
public DummyBluetoothGattCallback()
|
||||
public DummyBluetoothGattCallback (MidiDeviceManager mm)
|
||||
{
|
||||
super();
|
||||
owner = mm;
|
||||
}
|
||||
|
||||
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {}
|
||||
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
|
||||
{
|
||||
if (newState == BluetoothProfile.STATE_CONNECTED)
|
||||
{
|
||||
gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
|
||||
owner.pairBluetoothDeviceStepTwo (gatt.getDevice());
|
||||
}
|
||||
}
|
||||
public void onServicesDiscovered(BluetoothGatt gatt, int status) {}
|
||||
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}
|
||||
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}
|
||||
|
|
@ -506,6 +514,8 @@ public class MidiTest extends Activity
|
|||
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {}
|
||||
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {}
|
||||
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {}
|
||||
|
||||
private MidiDeviceManager owner;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -770,17 +780,28 @@ public class MidiTest extends Activity
|
|||
if (getBluetoothDeviceStatus (btAddress) != 0)
|
||||
return false;
|
||||
|
||||
BluetoothGatt gatt = btDevice.connectGatt (getApplicationContext(), true, new DummyBluetoothGattCallback());
|
||||
if (gatt != null)
|
||||
gatt.requestConnectionPriority (BluetoothGatt.CONNECTION_PRIORITY_HIGH);
|
||||
|
||||
btDevicesPairing.put (btDevice.getAddress(), gatt);
|
||||
manager.openBluetoothDevice(btDevice, this, null);
|
||||
btDevicesPairing.put (btDevice.getAddress(), null);
|
||||
BluetoothGatt gatt = btDevice.connectGatt (getApplicationContext(), true, new DummyBluetoothGattCallback (this));
|
||||
|
||||
if (gatt != null)
|
||||
{
|
||||
btDevicesPairing.put (btDevice.getAddress(), gatt);
|
||||
}
|
||||
else
|
||||
{
|
||||
pairBluetoothDeviceStepTwo (btDevice);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void pairBluetoothDeviceStepTwo (BluetoothDevice btDevice)
|
||||
{
|
||||
manager.openBluetoothDevice(btDevice, this, null);
|
||||
}
|
||||
|
||||
public void unpairBluetoothDevice (String address)
|
||||
{
|
||||
if (address.isEmpty())
|
||||
|
|
@ -936,11 +957,13 @@ public class MidiTest extends Activity
|
|||
MidiDeviceInfo info = theDevice.getInfo();
|
||||
int deviceID = info.getId();
|
||||
BluetoothGatt gatt = null;
|
||||
boolean isBluetooth = false;
|
||||
|
||||
if (! openTasks.containsKey (deviceID))
|
||||
{
|
||||
if (info.getType() == MidiDeviceInfo.TYPE_BLUETOOTH)
|
||||
{
|
||||
isBluetooth = true;
|
||||
BluetoothDevice btDevice = (BluetoothDevice) info.getProperties().get (info.PROPERTY_BLUETOOTH_DEVICE);
|
||||
if (btDevice != null)
|
||||
{
|
||||
|
|
@ -980,7 +1003,7 @@ public class MidiTest extends Activity
|
|||
MidiDeviceOpenTask openTask = new MidiDeviceOpenTask (this, theDevice, gatt);
|
||||
openTasks.put (deviceID, openTask);
|
||||
|
||||
new java.util.Timer().schedule (openTask, 3000);
|
||||
new java.util.Timer().schedule (openTask, (isBluetooth ? 2000 : 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue