Check for Google Play Services availability

This commit is contained in:
Michael Zanetti 2020-09-29 19:51:13 +02:00
parent 7e5cb35f90
commit 5fd2298de0
2 changed files with 21 additions and 41 deletions

View File

@ -69,6 +69,13 @@ PushNotifications *PushNotifications::instance()
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());
@ -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
}

View File

@ -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);
// }
}