Allow builds with firebase to work without play services again
parent
bc4c0cb7ca
commit
e69d7adbe9
|
|
@ -165,3 +165,5 @@ BR=$$BRANDING
|
|||
target.path = /usr/bin
|
||||
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.FirebaseMessagingService;
|
||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
|
|
@ -25,6 +27,18 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
|
|||
|
||||
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
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
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
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,12 +42,18 @@ static PushNotifications *m_client_pointer;
|
|||
PushNotifications::PushNotifications(QObject *parent) : QObject(parent)
|
||||
{
|
||||
#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);
|
||||
});
|
||||
qDebug() << "Checking for play services";
|
||||
jboolean playServicesAvailable = QAndroidJniObject::callStaticMethod<jboolean>("io.guh.nymeaapp.NymeaAppNotificationService", "checkPlayServices", "()Z");
|
||||
if (playServicesAvailable) {
|
||||
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);
|
||||
});
|
||||
} else {
|
||||
qDebug() << "Google Play Services not available. Cannot connect to push client.";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue