Allow building without firebase
parent
a1550d6bf7
commit
0b5b689101
|
|
@ -9,3 +9,5 @@ Thumbs.db
|
|||
/.qmake.stash
|
||||
|
||||
*.pro.user*
|
||||
|
||||
packaging/android/nymeaapp.properties
|
||||
|
|
|
|||
|
|
@ -54,10 +54,3 @@ DISTFILES += \
|
|||
java/io/guh/nymeaapp/State.java \
|
||||
java/io/guh/nymeaapp/NymeaHost.java \
|
||||
controlviews/Main.qml
|
||||
|
||||
QMAKE_COPY_DIR=cp -f -R -v
|
||||
javafiles.commands = $(MKDIR) $${ANDROID_PACKAGE_SOURCE_DIR}/src;
|
||||
javafiles.commands += $(COPY_DIR) $${PWD}/java/io $${ANDROID_PACKAGE_SOURCE_DIR}/src/
|
||||
QMAKE_EXTRA_TARGETS += javafiles
|
||||
POST_TARGETDEPS += javafiles
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ android: {
|
|||
} else {
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $${top_srcdir}/packaging/android
|
||||
}
|
||||
message("Andorid package source dir $${ANDROID_PACKAGE_SOURCE_DIR}")
|
||||
|
||||
!no-firebase:DEFINES+=WITH_FIREBASE
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,10 +82,16 @@ icons.path = /usr/share/
|
|||
INSTALLS += desktopfile icons
|
||||
}
|
||||
|
||||
# Android service
|
||||
android: {
|
||||
SUBDIRS += androidservice
|
||||
androidservice.depends = libnymea-app
|
||||
message("Android package source dir $${ANDROID_PACKAGE_SOURCE_DIR}")
|
||||
SUBDIRS += androidservice
|
||||
androidservice.depends = libnymea-app
|
||||
|
||||
NYMEA_APP_ROOT_PROPERTY="nymeaAppRoot=$${top_srcdir}"
|
||||
no-firebase: FIREBASE_PROPERTY="useFirebase=false"
|
||||
else: FIREBASE_PROPERTY="useFirebase=true"
|
||||
write_file($${ANDROID_PACKAGE_SOURCE_DIR}/nymeaapp.properties, NYMEA_APP_ROOT_PROPERTY)
|
||||
write_file($${ANDROID_PACKAGE_SOURCE_DIR}/nymeaapp.properties, FIREBASE_PROPERTY, append)
|
||||
}
|
||||
|
||||
# Linux desktop (snap package)
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ int main(int argc, char *argv[])
|
|||
qmlRegisterSingletonType<NfcHelper>("Nymea", 1, 0, "NfcHelper", NfcHelper::nfcHelperProvider);
|
||||
qmlRegisterType<NfcThingActionWriter>("Nymea", 1, 0, "NfcThingActionWriter");
|
||||
|
||||
PushNotifications::instance()->connectClient();
|
||||
qmlRegisterSingletonType<PushNotifications>("Nymea", 1, 0, "PushNotifications", PushNotifications::pushNotificationsProvider);
|
||||
qmlRegisterSingletonType<AppLogController>("Nymea", 1, 0, "AppLogController", AppLogController::appLogControllerProvider);
|
||||
qmlRegisterSingletonType(QUrl("qrc:///ui/utils/NymeaUtils.qml"), "Nymea", 1, 0, "NymeaUtils" );
|
||||
|
|
|
|||
|
|
@ -52,19 +52,8 @@ win32 {
|
|||
|
||||
android {
|
||||
|
||||
android-clang {
|
||||
FIREBASE_STL_VARIANT = c++
|
||||
}
|
||||
|
||||
isEmpty(FIREBASE_STL_VARIANT){
|
||||
FIREBASE_STL_VARIANT = gnustl
|
||||
}
|
||||
|
||||
include(../android_openssl/openssl.pri)
|
||||
|
||||
INCLUDEPATH += /opt/firebase_cpp_sdk/include
|
||||
LIBS += -L/opt/firebase_cpp_sdk/libs/android/$$ANDROID_TARGET_ARCH/$$FIREBASE_STL_VARIANT/ -lfirebase_messaging -lfirebase_app
|
||||
|
||||
QT += androidextras webview
|
||||
HEADERS += platformintegration/android/platformhelperandroid.h
|
||||
SOURCES += platformintegration/android/platformhelperandroid.cpp
|
||||
|
|
@ -83,14 +72,18 @@ android {
|
|||
$$ANDROID_PACKAGE_SOURCE_DIR/gradlew.bat \
|
||||
$$ANDROID_PACKAGE_SOURCE_DIR/LICENSE \
|
||||
platformintegration/android/java/io/guh/nymeaapp/NymeaAppActivity.java \
|
||||
platformintegration/android/java/io/guh/nymeaapp/NymeaAppNotificationService.java \
|
||||
platformintegration/android/java-firebase/io/guh/nymeaapp/NymeaAppNotificationService.java \
|
||||
|
||||
QMAKE_COPY_DIR=cp -f -R -v
|
||||
QMAKE_MKDIR_COMMAND=echo tralala; mkdir
|
||||
javafiles.commands = $(MKDIR) $${ANDROID_PACKAGE_SOURCE_DIR}/src/;
|
||||
javafiles.commands += $(COPY_DIR) $${PWD}/platformintegration/android/java/io $${ANDROID_PACKAGE_SOURCE_DIR}/src/;
|
||||
QMAKE_EXTRA_TARGETS += javafiles
|
||||
POST_TARGETDEPS += javafiles
|
||||
!no-firebase: {
|
||||
android-clang {
|
||||
FIREBASE_STL_VARIANT = c++
|
||||
}
|
||||
isEmpty(FIREBASE_STL_VARIANT){
|
||||
FIREBASE_STL_VARIANT = gnustl
|
||||
}
|
||||
INCLUDEPATH += /opt/firebase_cpp_sdk/include
|
||||
LIBS += -L/opt/firebase_cpp_sdk/libs/android/$$ANDROID_TARGET_ARCH/$$FIREBASE_STL_VARIANT/ -lfirebase_messaging -lfirebase_app
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -172,11 +165,3 @@ BR=$$BRANDING
|
|||
target.path = /usr/bin
|
||||
INSTALLS += target
|
||||
|
||||
contains(ANDROID_TARGET_ARCH,) {
|
||||
ANDROID_ABIS = \
|
||||
armeabi-v7a \
|
||||
arm64-v8a
|
||||
}
|
||||
|
||||
ANDROID_ABIS = armeabi-v7a arm64-v8a
|
||||
|
||||
|
|
|
|||
|
|
@ -25,28 +25,8 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
|
|||
|
||||
private static final String TAG = "nymea-app: NymeaAppNotificationService";
|
||||
|
||||
/**
|
||||
* Called when message is received.
|
||||
*
|
||||
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
|
||||
*/
|
||||
// [START receive_message]
|
||||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
// If the application is in the foreground handle both data and notification messages here.
|
||||
// Also if you intend on generating your own notifications as a result of a received FCM
|
||||
// message, here is where that should be initiated. See sendNotification method below.
|
||||
sendNotification(remoteMessage);
|
||||
}
|
||||
// [END receive_message]
|
||||
|
||||
/**
|
||||
* Create and show a simple notification containing the received FCM message.
|
||||
*
|
||||
* @param remoteMessage FCM RemoteMessage received.
|
||||
*/
|
||||
private void sendNotification(RemoteMessage remoteMessage) {
|
||||
|
||||
Intent intent = new Intent(this, NymeaAppActivity.class);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
|
|
@ -6,8 +6,6 @@ import android.os.Bundle;
|
|||
import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.provider.Settings.Secure;
|
||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import android.os.Vibrator;
|
||||
|
||||
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
|
||||
|
|
@ -34,16 +32,6 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
|
|||
return Build.DEVICE;
|
||||
}
|
||||
|
||||
public boolean checkPlayServices() {
|
||||
try {
|
||||
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
|
||||
return resultCode == ConnectionResult.SUCCESS;
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, e.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void vibrate(int duration)
|
||||
{
|
||||
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#if defined Q_OS_ANDROID
|
||||
#include <QtAndroid>
|
||||
#include <QtAndroidExtras>
|
||||
#include <QAndroidJniObject>
|
||||
|
|
@ -41,7 +41,15 @@ static PushNotifications *m_client_pointer;
|
|||
|
||||
PushNotifications::PushNotifications(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connectClient();
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
qDebug() << "Setting up firebase";
|
||||
m_client_pointer = this;
|
||||
m_firebaseApp = ::firebase::App::Create(::firebase::AppOptions(), QAndroidJniEnvironment(), QtAndroid::androidActivity().object());
|
||||
m_firebase_initializer.Initialize(m_firebaseApp, nullptr, [](::firebase::App * fapp, void *) {
|
||||
return ::firebase::messaging::Initialize( *fapp, (::firebase::messaging::Listener *)m_client_pointer);
|
||||
});
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UBPORTS
|
||||
m_pushClient = new PushClient(this);
|
||||
|
|
@ -53,6 +61,13 @@ PushNotifications::PushNotifications(QObject *parent) : QObject(parent)
|
|||
#endif
|
||||
}
|
||||
|
||||
PushNotifications::~PushNotifications()
|
||||
{
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
::firebase::messaging::Terminate();
|
||||
#endif
|
||||
}
|
||||
|
||||
QObject *PushNotifications::pushNotificationsProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
|
|
@ -66,34 +81,6 @@ PushNotifications *PushNotifications::instance()
|
|||
return pushNotifications;
|
||||
}
|
||||
|
||||
void PushNotifications::connectClient()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
||||
jboolean playServicesAvailable = QtAndroid::androidActivity().callMethod<jboolean>("checkPlayServices", "()Z");
|
||||
if (!playServicesAvailable) {
|
||||
qDebug() << "Google Play Services not available. Cannot connect to push client";
|
||||
return;
|
||||
}
|
||||
|
||||
m_firebaseApp = ::firebase::App::Create(::firebase::AppOptions(), QAndroidJniEnvironment(),
|
||||
QtAndroid::androidActivity().object());
|
||||
|
||||
m_client_pointer = this;
|
||||
|
||||
m_firebase_initializer.Initialize(m_firebaseApp, nullptr, [](::firebase::App * fapp, void *) {
|
||||
return ::firebase::messaging::Initialize( *fapp, (::firebase::messaging::Listener *)m_client_pointer);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void PushNotifications::disconnectClient()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
::firebase::messaging::Terminate();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString PushNotifications::token() const
|
||||
{
|
||||
return m_token;
|
||||
|
|
@ -106,7 +93,7 @@ void PushNotifications::setAPNSRegistrationToken(const QString &apnsRegistration
|
|||
emit tokenChanged();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
void PushNotifications::OnMessage(const firebase::messaging::Message &message)
|
||||
{
|
||||
qDebug() << "Firebase message received:" << QString::fromStdString(message.from);
|
||||
|
|
|
|||
|
|
@ -34,18 +34,17 @@
|
|||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
#include "firebase/app.h"
|
||||
#include "firebase/messaging.h"
|
||||
#include "firebase/util.h"
|
||||
|
||||
#elif UBPORTS
|
||||
|
||||
#include "platformintegration/ubports/pushclient.h"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#if defined UBPORTS
|
||||
#include "platformintegration/ubports/pushclient.h"
|
||||
#endif
|
||||
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
class PushNotifications : public QObject, firebase::messaging::Listener
|
||||
#else
|
||||
class PushNotifications : public QObject
|
||||
|
|
@ -56,13 +55,11 @@ class PushNotifications : public QObject
|
|||
|
||||
public:
|
||||
explicit PushNotifications(QObject *parent = nullptr);
|
||||
~PushNotifications();
|
||||
|
||||
static QObject* pushNotificationsProvider(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||
static PushNotifications* instance();
|
||||
|
||||
void connectClient();
|
||||
void disconnectClient();
|
||||
|
||||
QString token() const;
|
||||
|
||||
// Called by Objective-C++
|
||||
|
|
@ -72,18 +69,18 @@ signals:
|
|||
void tokenChanged();
|
||||
|
||||
protected:
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||
//! Firebase overrides
|
||||
virtual void OnMessage(const ::firebase::messaging::Message &message) override;
|
||||
virtual void OnTokenReceived(const char *token) override;
|
||||
private:
|
||||
::firebase::App *m_firebaseApp = nullptr;
|
||||
::firebase::ModuleInitializer m_firebase_initializer;
|
||||
#endif
|
||||
|
||||
#elif UBPORTS
|
||||
|
||||
#if defined UBPORTS
|
||||
PushClient *m_pushClient = nullptr;
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,13 @@
|
|||
// Loading nymeapp.properties. This file must be generated by the .pro file
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file("nymeaapp.properties").newDataInputStream())
|
||||
|
||||
def nymeaAppRoot = properties.getProperty('nymeaAppRoot')
|
||||
def useFirebase = properties.getProperty('useFirebase')
|
||||
|
||||
println "Building Android package"
|
||||
println "Package source root ${nymeaAppRoot}"
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
|
|
@ -26,15 +36,20 @@ allprojects {
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.google.android.gms:play-services-base:15.0.1'
|
||||
compile 'com.google.firebase:firebase-messaging:18.0.0'
|
||||
compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'org.reactivestreams:reactive-streams:1.0.3'
|
||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
|
||||
|
||||
if ("${useFirebase}" == "true") {
|
||||
implementation 'com.google.android.gms:play-services-base:15.0.1'
|
||||
implementation 'com.google.firebase:firebase-messaging:18.0.0'
|
||||
implementation 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
if ("${useFirebase}" == "true") {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
}
|
||||
|
||||
android {
|
||||
/*******************************************************
|
||||
|
|
@ -57,7 +72,16 @@ android {
|
|||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
|
||||
java.srcDirs = [
|
||||
qt5AndroidDir + '/src',
|
||||
nymeaAppRoot + '/androidservice/java',
|
||||
nymeaAppRoot + '/nymea-app/platformintegration/android/java',
|
||||
'src',
|
||||
'java']
|
||||
if ("${useFirebase}" == "true") {
|
||||
java.srcDirs += [nymeaAppRoot + '/nymea-app/platformintegration/android/java-firebase']
|
||||
}
|
||||
|
||||
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
|
||||
res.srcDirs = [qt5AndroidDir + '/res', 'res']
|
||||
resources.srcDirs = ['src']
|
||||
|
|
|
|||
Loading…
Reference in New Issue