1
1
package io .fullstack .firestack ;
2
2
3
+ import java .util .HashMap ;
3
4
import java .util .Map ;
4
5
5
6
import android .util .Log ;
17
18
import com .facebook .react .bridge .ReactContext ;
18
19
19
20
import com .google .android .gms .common .ConnectionResult ;
20
- //import com.google.android.gms.common.GooglePlayServicesUtil;
21
+ import com .google .android .gms .common .GoogleApiAvailability ;
22
+
21
23
import com .google .firebase .FirebaseApp ;
22
24
import com .google .firebase .FirebaseOptions ;
23
25
import com .google .firebase .database .ServerValue ;
@@ -27,7 +29,7 @@ interface KeySetterFn {
27
29
}
28
30
29
31
@ SuppressWarnings ("WeakerAccess" )
30
- class FirestackModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
32
+ public class FirestackModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
31
33
private static final String TAG = "Firestack" ;
32
34
private Context context ;
33
35
private ReactContext mReactContext ;
@@ -46,18 +48,20 @@ public String getName() {
46
48
return TAG ;
47
49
}
48
50
49
- // private static Boolean hasValidPlayServices() {
50
- // final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.context);
51
- // if (status != ConnectionResult.SUCCESS) {
52
- // Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
53
- // Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, 1);
54
- // dialog.show();
55
- // return false;
56
- // } else {
57
- // Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
58
- // return true;
59
- // }
60
- // }
51
+ private WritableMap getPlayServicesStatus () {
52
+ GoogleApiAvailability gapi = GoogleApiAvailability .getInstance ();
53
+ final int status = gapi .isGooglePlayServicesAvailable (getReactApplicationContext ());
54
+ WritableMap result = Arguments .createMap ();
55
+ result .putInt ("status" , status );
56
+ if (status == ConnectionResult .SUCCESS ) {
57
+ result .putBoolean ("isAvailable" , true );
58
+ } else {
59
+ result .putBoolean ("isAvailable" , false );
60
+ result .putBoolean ("isUserResolvableError" , gapi .isUserResolvableError (status ));
61
+ result .putString ("error" , gapi .getErrorString (status ));
62
+ }
63
+ return result ;
64
+ }
61
65
62
66
@ ReactMethod
63
67
public void configureWithOptions (final ReadableMap params , @ Nullable final Callback onComplete ) {
@@ -198,4 +202,11 @@ public void onHostPause() {
198
202
public void onHostDestroy () {
199
203
200
204
}
205
+
206
+ @ Override
207
+ public Map <String , Object > getConstants () {
208
+ final Map <String , Object > constants = new HashMap <>();
209
+ constants .put ("googleApiAvailability" , getPlayServicesStatus ());
210
+ return constants ;
211
+ }
201
212
}
0 commit comments