Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
servicediscoverybroadcastreceiver.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QCoreApplication>
6#include <QtCore/QLoggingCategory>
7#include <QtCore/QJniEnvironment>
8#include <QtBluetooth/QBluetoothAddress>
9#include <QtBluetooth/QBluetoothDeviceInfo>
11
13
14Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
15
17{
18 addAction(valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionUuid>());
19}
20
21void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, jobject intent)
22{
24 Q_UNUSED(env);
25
26 QJniObject intentObject(intent);
27 const QString action = intentObject.callMethod<jstring>("getAction").toString();
28
29 qCDebug(QT_BT_ANDROID) << "ServiceDiscoveryBroadcastReceiver::onReceive() - event:" << action;
30
31 if (action == valueForStaticField<QtJniTypes::BluetoothDevice,
33
34 QJniObject keyExtra = valueForStaticField<QtJniTypes::BluetoothDevice,
36 QJniObject parcelableUuids = intentObject.callMethod<QtJniTypes::ParcelableArray>(
37 "getParcelableArrayExtra",
38 keyExtra.object<jstring>());
39 if (!parcelableUuids.isValid()) {
41 return;
42 }
44
45 keyExtra = valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ExtraDevice>();
46 QJniObject bluetoothDevice =
47 intentObject.callMethod<QtJniTypes::Parcelable>("getParcelableExtra",
48 keyExtra.object<jstring>());
50 if (bluetoothDevice.isValid()) {
51 address =
52 QBluetoothAddress(bluetoothDevice.callMethod<jstring>("getAddress").toString());
54 } else {
56 }
57 }
58}
59
61{
64
65 jobjectArray parcels = parcelUuidArray.object<jobjectArray>();
66 if (!parcels)
67 return result;
68
69 jint size = env->GetArrayLength(parcels);
70 for (jint i = 0; i < size; ++i) {
71 auto p = QJniObject::fromLocalRef(env->GetObjectArrayElement(parcels, i));
72
73 QBluetoothUuid uuid(p.callMethod<jstring>("toString").toString());
74 //qCDebug(QT_BT_ANDROID) << uuid.toString();
75 result.append(uuid);
76 }
77
78 return result;
79}
80
82
\inmodule QtBluetooth
\inmodule QtBluetooth
\inmodule QtCore
\inmodule QtCore
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
virtual void onReceive(JNIEnv *env, jobject context, jobject intent)
void uuidFetchFinished(const QBluetoothAddress &addr, const QList< QBluetoothUuid > &serviceUuid)
static QList< QBluetoothUuid > convertParcelableArray(const QJniObject &obj)
@ ExtraUuid
@ ActionUuid
QJniObject valueForStaticField()
Combined button and popup list for selecting options.
static void * context
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint64EXT address
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define emit
#define Q_UNUSED(x)
char * toString(const MyType &t)
[31]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent