5package org.qtproject.qt.android.bluetooth;
12import android.content.BroadcastReceiver;
17import java.lang.reflect.Method;
18import java.util.HashSet;
21class QtBluetoothBroadcastReceiver
extends BroadcastReceiver
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;
35 static final String ACTION_REQUEST_DISABLE =
36 "android.bluetooth.adapter.action.REQUEST_DISABLE";
38 private static final String TAG =
"QtBluetoothBroadcastReceiver";
43 synchronized (qtContext) {
47 jniOnReceive(qtObject,
context, intent);
51 void unregisterReceiver()
53 synchronized (qtContext) {
56 qtContext.unregisterReceiver(
this);
57 }
catch (Exception ex) {
58 Log.d(
TAG,
"Trying to unregister a BroadcastReceiver which is not yet registered");
63 native
void jniOnReceive(
long qtObject,
Context context, Intent intent);
70 static boolean setDisabled()
72 if (!(qtContext instanceof
android.app.Activity)) {
73 Log.w(
TAG,
"Bluetooth cannot be disabled from a service.");
78 Intent intent =
new Intent(ACTION_REQUEST_DISABLE);
81 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISABLED);
82 }
catch (Exception ex) {
83 Log.w(
TAG,
"setDisabled() failed to initiate Bluetooth disablement");
90 static boolean setDiscoverable()
92 if (!(qtContext instanceof
android.app.Activity)) {
93 Log.w(
TAG,
"Discovery mode cannot be enabled from a service.");
100 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISCOVERABLE);
101 }
catch (Exception ex) {
102 Log.w(
TAG,
"setDiscoverable() failed to initiate Bluetooth discoverability change");
103 ex.printStackTrace();
109 static boolean setEnabled()
111 if (!(qtContext instanceof
android.app.Activity)) {
112 Log.w(
TAG,
"Bluetooth cannot be enabled from a service.");
118 ((Activity)qtContext).startActivityForResult(intent, TURN_BT_ENABLED);
119 }
catch (Exception ex) {
120 Log.w(
TAG,
"setEnabled() failed to initiate Bluetooth enablement");
121 ex.printStackTrace();
127 static boolean setPairingMode(
String address,
boolean isPairing)
130 (BluetoothManager)qtContext.getSystemService(
Context.BLUETOOTH_SERVICE);
148 }
catch (Exception ex) {
149 ex.printStackTrace();
163 static String[] getConnectedDevices()
165 BluetoothManager bluetoothManager =
166 (BluetoothManager) qtContext.getSystemService(
Context.BLUETOOTH_SERVICE);
168 if (bluetoothManager ==
null) {
169 Log.w(
TAG,
"Failed to retrieve connected devices");
174 bluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
176 bluetoothManager.getConnectedDevices(BluetoothProfile.GATT_SERVER);
179 HashSet<String>
set =
new HashSet<String>();
180 for (
Object gattConnection : gattConnections)
181 set.add(gattConnection.toString());
183 for (
Object gattServerConnection : gattServerConnections)
184 set.add(gattServerConnection.toString());
IOBluetoothDevice * device
static const QString context()
[vector_of_multirole_objects_0]
static QString methodName(const QDBusIntrospection::Method &method)
GLenum GLuint GLintptr GLsizeiptr size
GLuint GLuint64EXT address
QNetworkAccessManager manager
[0]