Allow builds with firebase to work without play services again
This commit is contained in:
parent
bc4c0cb7ca
commit
e69d7adbe9
@ -165,3 +165,5 @@ BR=$$BRANDING
|
|||||||
target.path = /usr/bin
|
target.path = /usr/bin
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
|
ANDROID_ABIS = armeabi-v7a arm64-v8a
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package io.guh.nymeaapp;
|
|||||||
|
|
||||||
import com.google.firebase.messaging.RemoteMessage;
|
import com.google.firebase.messaging.RemoteMessage;
|
||||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||||
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||||
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -25,6 +27,18 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
|
|||||||
|
|
||||||
private static final String TAG = "nymea-app: NymeaAppNotificationService";
|
private static final String TAG = "nymea-app: NymeaAppNotificationService";
|
||||||
|
|
||||||
|
public static boolean checkPlayServices() {
|
||||||
|
Log.d(TAG, "Checking for Google Play services");
|
||||||
|
try {
|
||||||
|
Context context = NymeaAppActivity.getAppContext();
|
||||||
|
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
|
||||||
|
return resultCode == ConnectionResult.SUCCESS;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, e.toString());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||||
Intent intent = new Intent(this, NymeaAppActivity.class);
|
Intent intent = new Intent(this, NymeaAppActivity.class);
|
||||||
|
|||||||
@ -11,6 +11,17 @@ import android.os.Vibrator;
|
|||||||
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
|
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
|
||||||
{
|
{
|
||||||
private static final String TAG = "nymea-app: NymeaAppActivity";
|
private static final String TAG = "nymea-app: NymeaAppActivity";
|
||||||
|
private static Context context = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
this.context = getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Context getAppContext() {
|
||||||
|
return NymeaAppActivity.context;
|
||||||
|
}
|
||||||
|
|
||||||
public String deviceSerial()
|
public String deviceSerial()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -42,12 +42,18 @@ static PushNotifications *m_client_pointer;
|
|||||||
PushNotifications::PushNotifications(QObject *parent) : QObject(parent)
|
PushNotifications::PushNotifications(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
#if defined Q_OS_ANDROID && defined WITH_FIREBASE
|
||||||
qDebug() << "Setting up firebase";
|
qDebug() << "Checking for play services";
|
||||||
m_client_pointer = this;
|
jboolean playServicesAvailable = QAndroidJniObject::callStaticMethod<jboolean>("io.guh.nymeaapp.NymeaAppNotificationService", "checkPlayServices", "()Z");
|
||||||
m_firebaseApp = ::firebase::App::Create(::firebase::AppOptions(), QAndroidJniEnvironment(), QtAndroid::androidActivity().object());
|
if (playServicesAvailable) {
|
||||||
m_firebase_initializer.Initialize(m_firebaseApp, nullptr, [](::firebase::App * fapp, void *) {
|
qDebug() << "Setting up firebase";
|
||||||
return ::firebase::messaging::Initialize( *fapp, (::firebase::messaging::Listener *)m_client_pointer);
|
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);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
qDebug() << "Google Play Services not available. Cannot connect to push client.";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user