-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcastbridgeandroid.cpp
More file actions
48 lines (42 loc) · 1.51 KB
/
castbridgeandroid.cpp
File metadata and controls
48 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "castbridgeandroid.h"
#include <QDebug>
#include <QtCore/private/qandroidextras_p.h>
#include <QtCore/private/qjnihelpers_p.h>
#include <QJniEnvironment>
CastBridgeAndroid::CastBridgeAndroid(QObject *parent)
: CastBridge{parent}
{
env_ = new QJniEnvironment();
}
CastBridgeAndroid::~CastBridgeAndroid() {
if (castHandle_) delete castHandle_;
delete env_;
}
bool CastBridgeAndroid::lowCreate(bool anotherThread) {
qDebug()<<">>cast.create " << (anotherThread ? "from another thread" : "from same thread");
if (!castHandle_) {
jclass javaClass = env_->findClass("test/cast/CastWrapper");
if (javaClass == NULL) {
qWarning() << "WARNING: Failed to find class "
"test/cast/Test";
return false;
}
castHandle_ = new QJniObject(javaClass,"(Z)V", anotherThread);
}
QJniObject ctx = QNativeInterface::QAndroidApplication::context();
auto succeeded = castHandle_->callMethod<jboolean>("createCast",
"(Landroid/content/Context;)Z",
ctx.object());
qDebug()<<"<<cast.create "<<succeeded;
return succeeded;
}
bool CastBridgeAndroid::lowRelease() {
if (!castHandle_) return false;
qDebug()<<">>cast.release";
auto succeeded = castHandle_->callMethod<jboolean>("releaseCast",
"()Z");
delete castHandle_;
castHandle_ = nullptr;
qDebug()<<"<<cast.release "<<succeeded;
return succeeded;
}