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
androidutils.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
4#include "androidutils_p.h"
5#include "jni_android_p.h"
6
7#include <QtCore/qcoreapplication.h>
8#include <QtCore/qloggingcategory.h>
9#include <QtCore/private/qandroidextras_p.h>
10
12
13Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
14
15bool ensureAndroidPermission(QBluetoothPermission::CommunicationModes modes)
16{
17 QBluetoothPermission permission;
18 permission.setCommunicationModes(modes);
19
20 if (qApp->checkPermission(permission) == Qt::PermissionStatus::Granted)
21 return true;
22
23 qCWarning(QT_BT_ANDROID) << "Permissions not authorized for a specified mode:" << modes;
24 return false;
25}
26
28{
29 QJniObject service = QJniObject::getStaticField<QtJniTypes::AndroidContext, jstring>(
30 "BLUETOOTH_SERVICE");
31 QJniObject context = QNativeInterface::QAndroidApplication::context();
33 context.callMethod<jobject>("getSystemService", service.object<jstring>());
34 QJniObject adapter;
35 if (manager.isValid())
36 adapter = manager.callMethod<QtJniTypes::BluetoothAdapter>("getAdapter");
37
38 // ### Qt 7 check if the below double-get of the adapter can be removed.
39 // It is a workaround for QTBUG-57489, fixed in 2016. According to the bug it occurred on
40 // a certain device running Android 6.0.1 (Qt 6 supports Android 6.0 as the minimum).
41 // For completeness: the original workaround was for the deprecated getDefaultAdapter()
42 // method, and it is thus unclear if this is needed even in Qt 6 anymore. In addition the
43 // impacted device is updateable to Android 8 which may also have fixed the issue.
44 if (!adapter.isValid())
45 adapter = manager.callMethod<QtJniTypes::BluetoothAdapter>("getAdapter");
46
47 return adapter;
48}
49
QJniObject getDefaultBluetoothAdapter()
QT_BEGIN_NAMESPACE bool ensureAndroidPermission(QBluetoothPermission::CommunicationModes modes)
Access Bluetooth peripherals.
Q_CORE_EXPORT void setCommunicationModes(CommunicationModes modes)
\inmodule QtCore
Combined button and popup list for selecting options.
static void * context
#define qApp
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QNetworkAccessManager manager