Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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(QJniObject::fromString(
19 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionUuid>()));
20}
21
22void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, jobject intent)
23{
25 Q_UNUSED(env);
26
27 QJniObject intentObject(intent);
28 const QString action = intentObject.callMethod<jstring>("getAction").toString();
29
30 qCDebug(QT_BT_ANDROID) << "ServiceDiscoveryBroadcastReceiver::onReceive() - event:" << action;
31
32 if (action == valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ActionUuid>()) {
33
34 QJniObject keyExtra = QJniObject::fromString(
35 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ExtraUuid>());
36 QJniObject parcelableUuids = intentObject.callMethod<QtJniTypes::ParcelableArray>(
37 "getParcelableArrayExtra",
38 keyExtra.object<jstring>());
39 if (!parcelableUuids.isValid()) {
40 emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
41 return;
42 }
43 const QList<QBluetoothUuid> result = ServiceDiscoveryBroadcastReceiver::convertParcelableArray(parcelableUuids);
44
45 keyExtra = QJniObject::fromString(
46 valueForStaticField<QtJniTypes::BluetoothDevice, JavaNames::ExtraDevice>());
47 QJniObject bluetoothDevice =
48 intentObject.callMethod<QtJniTypes::Parcelable>("getParcelableExtra",
49 keyExtra.object<jstring>());
51 if (bluetoothDevice.isValid()) {
52 address =
53 QBluetoothAddress(bluetoothDevice.callMethod<jstring>("getAddress").toString());
55 } else {
56 emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
57 }
58 }
59}
60
61QList<QBluetoothUuid> ServiceDiscoveryBroadcastReceiver::convertParcelableArray(const QJniObject &parcelUuidArray)
62{
63 QList<QBluetoothUuid> result;
65
66 jobjectArray parcels = parcelUuidArray.object<jobjectArray>();
67 if (!parcels)
68 return result;
69
70 jint size = env->GetArrayLength(parcels);
71 for (jint i = 0; i < size; ++i) {
72 auto p = QJniObject::fromLocalRef(env->GetObjectArrayElement(parcels, i));
73
74 QBluetoothUuid uuid(p.callMethod<jstring>("toString").toString());
75 //qCDebug(QT_BT_ANDROID) << uuid.toString();
76 result.append(uuid);
77 }
78
79 return result;
80}
81
83
\inmodule QtBluetooth
\inmodule QtBluetooth
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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)
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]