Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
androidbroadcastreceiver.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Lauri Laanmets (Proekspert AS) <lauri.laanmets@eesti.ee>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <android/log.h>
6#include <android/jni_android_p.h>
7#include "android/androidbroadcastreceiver_p.h"
8#include <QtCore/QLoggingCategory>
9#include <QtCore/qnativeinterface.h>
10#include <QtGui/QGuiApplication>
11
13
14Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
15
16
17AndroidBroadcastReceiver::AndroidBroadcastReceiver(QObject* parent)
18 : QObject(parent), valid(false)
19{
20 // get Qt Context
21 contextObject = QJniObject(QNativeInterface::QAndroidApplication::context());
22
23 broadcastReceiverObject = QJniObject::construct<QtJniTypes::QtBtBroadcastReceiver>();
24 if (!broadcastReceiverObject.isValid())
25 return;
26 broadcastReceiverObject.setField<jlong>("qtObject", reinterpret_cast<long>(this));
27
28 intentFilterObject = QJniObject::construct<QtJniTypes::IntentFilter>();
29 if (!intentFilterObject.isValid())
30 return;
31
32 valid = true;
33}
34
38
40{
41 return valid;
42}
43
45{
46 if (!valid)
47 return;
48
49 broadcastReceiverObject.callMethod<void>("unregisterReceiver");
50}
51
52void AndroidBroadcastReceiver::addAction(const QJniObject &action)
53{
54 if (!valid || !action.isValid())
55 return;
56
57 intentFilterObject.callMethod<void>("addAction", action.object<jstring>());
58
59 contextObject.callMethod<QtJniTypes::Intent>(
60 "registerReceiver",
61 broadcastReceiverObject.object<QtJniTypes::BroadcastReceiver>(),
62 intentFilterObject.object<QtJniTypes::IntentFilter>());
63}
64
65QT_END_NAMESPACE
void addAction(const QJniObject &filter)