diff options
Diffstat (limited to 'src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java')
-rw-r--r-- | src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index d2373051..59ed0992 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -53,6 +53,7 @@ import android.os.Looper; import android.util.Log; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Hashtable; @@ -61,6 +62,7 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; + public class QtBluetoothLE { private static final String TAG = "QtBluetoothGatt"; private final BluetoothAdapter mBluetoothAdapter; @@ -1315,6 +1317,32 @@ public class QtBluetoothLE { return modifiedHandle; } + // Directly called from public Qt API + public boolean requestConnectionUpdatePriority(double minimalInterval) + { + if (mBluetoothGatt == null) + return false; + + try { + //Android API v21 + Method connectionUpdateMethod = mBluetoothGatt.getClass().getDeclaredMethod( + "requestConnectionPriority", int.class); + if (connectionUpdateMethod == null) + return false; + + int requestPriority = 0; // BluetoothGatt.CONNECTION_PRIORITY_BALANCED + if (minimalInterval < 30) + requestPriority = 1; // BluetoothGatt.CONNECTION_PRIORITY_HIGH + else if (minimalInterval > 100) + requestPriority = 2; //BluetoothGatt/CONNECTION_PRIORITY_LOW_POWER + + Object result = connectionUpdateMethod.invoke(mBluetoothGatt, requestPriority); + return (Boolean) result; + } catch (Exception ex) { + return false; + } + } + public native void leConnectionStateChange(long qtObject, int wasErrorTransition, int newState); public native void leServicesDiscovered(long qtObject, int errorCode, String uuidList); public native void leServiceDetailDiscoveryFinished(long qtObject, final String serviceUuid, |