summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-20 08:39:04 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-10-28 13:59:43 +0100
commit04cb0d4af57cecdb6e47a6e2235083035580fa0d (patch)
treebcf62e2329f5aad1346f00b53e77c393dcc7961e /src/android
parenta7b0b599775864743d1436d3cbd9513f92eb2d06 (diff)
Android: Add BluetoothLE device scan
Change-Id: Ibbb1e9f141d494327082aebaf9e34ffe44039115 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/bluetooth/bluetooth.pri5
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java83
2 files changed, 86 insertions, 2 deletions
diff --git a/src/android/bluetooth/bluetooth.pri b/src/android/bluetooth/bluetooth.pri
index b2121ff3..16d3b612 100644
--- a/src/android/bluetooth/bluetooth.pri
+++ b/src/android/bluetooth/bluetooth.pri
@@ -1,5 +1,6 @@
CONFIG += java
DESTDIR = $$[QT_INSTALL_PREFIX/get]/jar
+API_VERSION = android-18
PATHPREFIX = $$PWD/src/org/qtproject/qt5/android/bluetooth
@@ -7,8 +8,8 @@ JAVACLASSPATH += $$PWD/src/
JAVASOURCES += \
$$PATHPREFIX/QtBluetoothBroadcastReceiver.java \
$$PATHPREFIX/QtBluetoothSocketServer.java \
- $$PATHPREFIX/QtBluetoothInputStreamThread.java
-
+ $$PATHPREFIX/QtBluetoothInputStreamThread.java \
+ $$PATHPREFIX/QtBluetoothLE.java
# install
target.path = $$[QT_INSTALL_PREFIX]/jar
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
new file mode 100644
index 00000000..8e36916a
--- /dev/null
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
@@ -0,0 +1,83 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/legal
+ **
+ ** This file is part of the QtBluetooth module of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL21$
+ ** Commercial License Usage
+ ** Licensees holding valid commercial Qt licenses may use this file in
+ ** accordance with the commercial license agreement provided with the
+ ** Software or, alternatively, in accordance with the terms contained in
+ ** a written agreement between you and Digia. For licensing terms and
+ ** conditions see http://qt.digia.com/licensing. For further information
+ ** use the contact form at http://qt.digia.com/contact-us.
+ **
+ ** GNU Lesser General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU Lesser
+ ** General Public License version 2.1 or version 3 as published by the Free
+ ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+ ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+ ** following information to ensure the GNU Lesser General Public License
+ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+ ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ **
+ ** In addition, as a special exception, Digia gives you certain additional
+ ** rights. These rights are described in the Digia Qt LGPL Exception
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+package org.qtproject.qt5.android.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+
+public class QtBluetoothLE {
+
+ private BluetoothAdapter mBluetoothAdapter;
+ private boolean mLeScanRunning = false;
+
+ /* Pointer to the Qt object that "owns" the Java object */
+ long qtObject = 0;
+
+ public QtBluetoothLE() {
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ }
+
+ /*
+ Returns true, if request was successfully completed
+ */
+ public boolean scanForLeDevice(final boolean isEnabled) {
+ if (isEnabled == mLeScanRunning)
+ return true;
+
+ if (isEnabled) {
+ mLeScanRunning = mBluetoothAdapter.startLeScan(leScanCallback);
+ } else {
+ mBluetoothAdapter.stopLeScan(leScanCallback);
+ mLeScanRunning = false;
+ }
+
+ return (mLeScanRunning == isEnabled);
+ }
+
+ // Device scan callback
+ private BluetoothAdapter.LeScanCallback leScanCallback =
+ new BluetoothAdapter.LeScanCallback() {
+
+ @Override
+ public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
+ if (qtObject == 0)
+ return;
+
+ leScanResult(qtObject, device, rssi);
+ }
+ };
+
+ public native void leScanResult(long qtObject, BluetoothDevice device, int rssi);
+}
+