[js][android] Use GoogleApiAvailability to prompt the user to install Google Play Services if it is not installed
This commit is contained in:
parent
90546aa7dd
commit
baa198ea7d
|
@ -3,12 +3,17 @@ package io.invertase.firebase;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// android
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
// react
|
// react
|
||||||
import com.facebook.react.bridge.Arguments;
|
import com.facebook.react.bridge.Arguments;
|
||||||
import com.facebook.react.bridge.WritableMap;
|
import com.facebook.react.bridge.WritableMap;
|
||||||
import com.facebook.react.bridge.LifecycleEventListener;
|
import com.facebook.react.bridge.LifecycleEventListener;
|
||||||
|
import com.facebook.react.bridge.Promise;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
// play services
|
// play services
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
|
@ -27,6 +32,16 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
|
||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void promptPlayServices() {
|
||||||
|
GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
|
||||||
|
int status = gapi.isGooglePlayServicesAvailable(getReactApplicationContext());
|
||||||
|
|
||||||
|
if (status != ConnectionResult.SUCCESS && gapi.isUserResolvableError(status)) {
|
||||||
|
gapi.getErrorDialog(getCurrentActivity(), status, 2404).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private WritableMap getPlayServicesStatus() {
|
private WritableMap getPlayServicesStatus() {
|
||||||
GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
|
GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
|
||||||
final int status = gapi.isGooglePlayServicesAvailable(getReactApplicationContext());
|
final int status = gapi.isGooglePlayServicesAvailable(getReactApplicationContext());
|
||||||
|
|
|
@ -54,7 +54,7 @@ export default class Firebase {
|
||||||
constructor(options: Object = {}) {
|
constructor(options: Object = {}) {
|
||||||
this.eventHandlers = {};
|
this.eventHandlers = {};
|
||||||
this.debug = options.debug || false;
|
this.debug = options.debug || false;
|
||||||
this.options = Object.assign({ errorOnMissingPlayServices: true }, options);
|
this.options = Object.assign({ errorOnMissingPlayServices: true, promptOnMissingPlayServices: true }, options);
|
||||||
|
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
Log.enable(this.debug);
|
Log.enable(this.debug);
|
||||||
|
@ -62,8 +62,17 @@ export default class Firebase {
|
||||||
|
|
||||||
this._log = new Log('firebase');
|
this._log = new Log('firebase');
|
||||||
|
|
||||||
if (this.options.errorOnMissingPlayServices && !this.googleApiAvailability.isAvailable) {
|
if (!this.googleApiAvailability.isAvailable) {
|
||||||
throw new Error(`Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`);
|
if (this.options.promptOnMissingPlayServices && this.googleApiAvailability.isUserResolvableError) {
|
||||||
|
FirebaseModule.promptPlayServices();
|
||||||
|
} else {
|
||||||
|
const error = `Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`;
|
||||||
|
if (this.options.errorOnMissingPlayServices) {
|
||||||
|
throw new Error(error);
|
||||||
|
} else {
|
||||||
|
console.warn(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.auth = this._staticsOrInstance('auth', AuthStatics, Auth);
|
this.auth = this._staticsOrInstance('auth', AuthStatics, Auth);
|
||||||
|
|
Loading…
Reference in New Issue