From 5fd2298de04daca5cf8a1b7a1a08358ff8d8afe4 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 29 Sep 2020 19:51:13 +0200 Subject: [PATCH] Check for Google Play Services availability --- nymea-app/pushnotifications.cpp | 13 ++--- .../src/io/guh/nymeaapp/NymeaAppActivity.java | 49 ++++++------------- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/nymea-app/pushnotifications.cpp b/nymea-app/pushnotifications.cpp index 8cf2cf4e..1e8c170e 100644 --- a/nymea-app/pushnotifications.cpp +++ b/nymea-app/pushnotifications.cpp @@ -69,6 +69,13 @@ PushNotifications *PushNotifications::instance() void PushNotifications::connectClient() { #ifdef Q_OS_ANDROID + + jboolean playServicesAvailable = QtAndroid::androidActivity().callMethod("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()); @@ -77,12 +84,6 @@ void PushNotifications::connectClient() m_firebase_initializer.Initialize(m_firebaseApp, nullptr, [](::firebase::App * fapp, void *) { return ::firebase::messaging::Initialize( *fapp, (::firebase::messaging::Listener *)m_client_pointer); }); - - while (m_firebase_initializer.InitializeLastResult().status() != - firebase::kFutureStatusComplete) { - - qDebug() << "Firebase: InitializeLastResult wait..."; - } #endif } diff --git a/packaging/android/src/io/guh/nymeaapp/NymeaAppActivity.java b/packaging/android/src/io/guh/nymeaapp/NymeaAppActivity.java index 0abd2ec5..6da47c08 100644 --- a/packaging/android/src/io/guh/nymeaapp/NymeaAppActivity.java +++ b/packaging/android/src/io/guh/nymeaapp/NymeaAppActivity.java @@ -6,10 +6,14 @@ 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 { + private static final String TAG = "nymea-app: NymeaAppActivity"; + public String deviceSerial() { return Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); @@ -30,44 +34,19 @@ 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); v.vibrate(duration); } - -// // The key in the intent's extras that maps to the incoming message's message ID. Only sent by -// // the server, GmsCore sends EXTRA_MESSAGE_ID_KEY below. Server can't send that as it would get -// // stripped by the client. -// private static final String EXTRA_MESSAGE_ID_KEY_SERVER = "message_id"; - -// // An alternate key value in the intent's extras that also maps to the incoming message's message -// // ID. Used by upstream, and set by GmsCore. -// private static final String EXTRA_MESSAGE_ID_KEY = "google.message_id"; - -// // The key in the intent's extras that maps to the incoming message's sender value. -// private static final String EXTRA_FROM = "google.message_id"; - - -// @Override -// protected void onNewIntent(Intent intent) -// { -// Bundle extras = intent.getExtras(); -// String from = extras.getString(EXTRA_FROM); -// String messageId = extras.getString(EXTRA_MESSAGE_ID_KEY); -// Log.d("*************** messageid", messageId); -//// Log.d("Bundle", extras); - -// if (messageId == null) { -// messageId = extras.getString(EXTRA_MESSAGE_ID_KEY_SERVER); -// } -// // if (from != null && messageId != null) { -// Intent message = new Intent(this, MessageForwardingService.class); -// message.setAction(MessageForwardingService.ACTION_REMOTE_INTENT); -// message.putExtras(intent); -// message.setData(intent.getData()); -// startService(message); -// // } -// setIntent(intent); -// } }