5package org.qtproject.qt.android.bluetooth;
7import android.app.Activity;
8import android.bluetooth.BluetoothAdapter;
9import android.bluetooth.BluetoothDevice;
10import android.bluetooth.BluetoothProfile;
11import android.bluetooth.BluetoothManager;
12import android.content.BroadcastReceiver;
13import android.content.Context;
14import android.content.Intent;
15import android.util.Log;
17import java.lang.reflect.Method;
18import java.util.HashSet;
24 @SuppressWarnings(
"WeakerAccess")
26 @SuppressWarnings(
"WeakerAccess")
27 static Context qtContext =
null;
30 private static final int TURN_BT_ENABLED = 3330;
31 private static final int TURN_BT_DISCOVERABLE = 3331;
32 private static final int TURN_BT_DISABLED = 3332;
36 "android.bluetooth.adapter.action.REQUEST_DISABLE";
38 private static final String TAG =
"QtBluetoothBroadcastReceiver";
42 synchronized (qtContext) {
52 synchronized (qtContext) {
55 qtContext.unregisterReceiver(
this);
56 }
catch (Exception ex) {
57 Log.d(
TAG,
"Trying to unregister a BroadcastReceiver which is not yet registered");
71 if (!(qtContext instanceof android.app.Activity)) {
72 Log.w(
TAG,
"Bluetooth cannot be disabled from a service.");
80 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISABLED);
81 }
catch (Exception ex) {
82 Log.w(
TAG,
"setDisabled() failed to initiate Bluetooth disablement");
91 if (!(qtContext instanceof android.app.Activity)) {
92 Log.w(
TAG,
"Discovery mode cannot be enabled from a service.");
99 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISCOVERABLE);
100 }
catch (Exception ex) {
101 Log.w(
TAG,
"setDiscoverable() failed to initiate Bluetooth discoverability change");
102 ex.printStackTrace();
110 if (!(qtContext instanceof android.app.Activity)) {
111 Log.w(
TAG,
"Bluetooth cannot be enabled from a service.");
117 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_ENABLED);
118 }
catch (Exception ex) {
119 Log.w(
TAG,
"setEnabled() failed to initiate Bluetooth enablement");
120 ex.printStackTrace();
129 (BluetoothManager)qtContext.getSystemService(Context.BLUETOOTH_SERVICE);
147 }
catch (Exception ex) {
148 ex.printStackTrace();
164 BluetoothManager bluetoothManager =
165 (BluetoothManager) qtContext.getSystemService(Context.BLUETOOTH_SERVICE);
167 if (bluetoothManager ==
null) {
168 Log.w(
TAG,
"Failed to retrieve connected devices");
169 return new String[0];
172 List<BluetoothDevice> gattConnections =
173 bluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
174 List<BluetoothDevice> gattServerConnections =
175 bluetoothManager.getConnectedDevices(BluetoothProfile.GATT_SERVER);
178 HashSet<String>
set =
new HashSet<String>();
179 for (
Object gattConnection : gattConnections)
180 set.
add(gattConnection.toString());
182 for (
Object gattServerConnection : gattServerConnections)
183 set.
add(gattServerConnection.toString());
185 return set.toArray(
new String[
set.
size()]);
IOBluetoothDevice * device
static boolean setDisabled()
static boolean setDiscoverable()
static boolean setPairingMode(String address, boolean isPairing)
void unregisterReceiver()
static void setContext(Context context)
static final String ACTION_REQUEST_DISABLE
native void jniOnReceive(long qtObject, Context context, Intent intent)
static String[] getConnectedDevices()
void onReceive(Context context, Intent intent)
static boolean setEnabled()
static QString methodName(const QDBusIntrospection::Method &method)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint64EXT address
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
QNetworkAccessManager manager