Skip to content

Instantly share code, notes, and snippets.

@alexHlebnikov
Created September 22, 2016 08:09
Show Gist options
  • Select an option

  • Save alexHlebnikov/b4ab7e25341dc9dc8cb6cd541f616a1b to your computer and use it in GitHub Desktop.

Select an option

Save alexHlebnikov/b4ab7e25341dc9dc8cb6cd541f616a1b to your computer and use it in GitHub Desktop.

Revisions

  1. alexHlebnikov created this gist Sep 22, 2016.
    53 changes: 53 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    package ru.doublegis.drugstores;

    import android.os.Bundle;
    import android.util.Log;

    import com.facebook.react.ReactActivity;
    import android.content.Intent;

    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.GoogleApiAvailability;

    public class MainActivity extends ReactActivity {

    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    checkPlayServices();
    }

    /**
    * Returns the name of the main component registered from JavaScript.
    * This is used to schedule rendering of the component.
    */
    @Override
    protected String getMainComponentName() {
    return "Drugstores";
    }

    /**
    * Check the device to make sure it has the Google Play Services APK. If
    * it doesn't, display a dialog that allows users to download the APK from
    * the Google Play Store or enable it in the device's system settings.
    */
    private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
    if (apiAvailability.isUserResolvableError(resultCode)) {
    apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
    .show();
    } else {
    Log.i(TAG, "This device is not supported.");
    finish();
    }
    return false;
    }
    return true;
    }
    }