Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
11
QT_BEGIN_NAMESPACE
12
13
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
14
15
bool
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
27
QJniObject
getDefaultBluetoothAdapter
()
28
{
29
QJniObject service = QJniObject::getStaticField<QtJniTypes::AndroidContext, jstring>(
30
"BLUETOOTH_SERVICE"
);
31
QJniObject context = QNativeInterface::QAndroidApplication::context();
32
QJniObject manager =
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
50
QT_END_NAMESPACE
getDefaultBluetoothAdapter
QJniObject getDefaultBluetoothAdapter()
Definition
androidutils.cpp:27
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtconnectivity
src
bluetooth
android
androidutils.cpp
Generated on
for Qt by
1.18.0