Search in sources :

Example 1 with GooglePlayServicesRepairableException

use of com.google.android.gms.common.GooglePlayServicesRepairableException in project open-event-orga-app by fossasia.

the class CreateEventFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.event_create_layout, container, false);
    validator = new Validator(binding.form);
    AppCompatActivity activity = ((AppCompatActivity) getActivity());
    activity.setSupportActionBar(binding.toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setHasOptionsMenu(true);
    binding.submit.setOnClickListener(view -> {
        if (validator.validate())
            getPresenter().createEvent();
    });
    // check if there's an google places API key
    try {
        ApplicationInfo ai = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        String placesApiKey = bundle.getString("com.google.android.geo.API_KEY");
        if ("YOUR_API_KEY".equals(placesApiKey)) {
            Timber.d("Add Google Places API key in AndroidManifest.xml file to use Place Picker.");
            binding.form.buttonPlacePicker.setVisibility(View.GONE);
            binding.form.layoutLatitude.setVisibility(View.VISIBLE);
            binding.form.layoutLongitude.setVisibility(View.VISIBLE);
            showLocationLayouts();
        }
    } catch (PackageManager.NameNotFoundException e) {
        Timber.e(e, "Package name not found");
    }
    binding.form.buttonPlacePicker.setOnClickListener(view -> {
        int errorCode = googleApiAvailabilityInstance.isGooglePlayServicesAvailable(getContext());
        if (errorCode == ConnectionResult.SUCCESS) {
            // SUCCESS
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            try {
                startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
            } catch (GooglePlayServicesRepairableException e) {
                Timber.d(e, "GooglePlayServicesRepairable");
            } catch (GooglePlayServicesNotAvailableException e) {
                Timber.d("GooglePlayServices NotAvailable => Updating or Unauthentic");
            }
        } else if (googleApiAvailabilityInstance.isUserResolvableError(errorCode)) {
            // SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED
            googleApiAvailabilityInstance.getErrorDialog(getActivity(), errorCode, PLACE_PICKER_REQUEST, (dialog) -> {
                showLocationLayouts();
            });
        } else {
            // SERVICE_UPDATING, SERVICE_INVALID - can't use place picker - must enter manually
            showLocationLayouts();
        }
    });
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return binding.getRoot();
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) ConnectionResult(com.google.android.gms.common.ConnectionResult) PackageManager(android.content.pm.PackageManager) RESULT_OK(android.app.Activity.RESULT_OK) Intent(android.content.Intent) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) Inject(javax.inject.Inject) EventCreateLayoutBinding(org.fossasia.openevent.app.databinding.EventCreateLayoutBinding) Validator(br.com.ilhasoft.support.validation.Validator) PlacePicker(com.google.android.gms.location.places.ui.PlacePicker) Toast(android.widget.Toast) View(android.view.View) Event(org.fossasia.openevent.app.data.models.Event) R(org.fossasia.openevent.app.R) BaseBottomSheetFragment(org.fossasia.openevent.app.common.mvp.view.BaseBottomSheetFragment) ActionBar(android.support.v7.app.ActionBar) ViewUtils.showView(org.fossasia.openevent.app.ui.ViewUtils.showView) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ViewUtils(org.fossasia.openevent.app.ui.ViewUtils) Lazy(dagger.Lazy) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) ArrayAdapter(android.widget.ArrayAdapter) ValidateUtils(org.fossasia.openevent.app.utils.ValidateUtils) List(java.util.List) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException) DataBindingUtil(android.databinding.DataBindingUtil) Function(org.fossasia.openevent.app.common.Function) Nullable(android.support.annotation.Nullable) ApplicationInfo(android.content.pm.ApplicationInfo) Place(com.google.android.gms.location.places.Place) GoogleApiAvailability(com.google.android.gms.common.GoogleApiAvailability) TextWatcher(android.text.TextWatcher) Bundle(android.os.Bundle) AppCompatActivity(android.support.v7.app.AppCompatActivity) ApplicationInfo(android.content.pm.ApplicationInfo) PlacePicker(com.google.android.gms.location.places.ui.PlacePicker) PackageManager(android.content.pm.PackageManager) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) Validator(br.com.ilhasoft.support.validation.Validator) ActionBar(android.support.v7.app.ActionBar) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException)

Example 2 with GooglePlayServicesRepairableException

use of com.google.android.gms.common.GooglePlayServicesRepairableException in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method openAutocompleteModal.

/**
 * Exposed React's methods
 */
@ReactMethod
public void openAutocompleteModal(ReadableMap options, final Promise promise) {
    this.pendingPromise = promise;
    String type = options.getString("type");
    String country = options.getString("country");
    country = country.isEmpty() ? null : country;
    boolean useOverlay = options.getBoolean("useOverlay");
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    Activity currentActivity = getCurrentActivity();
    try {
        // The autocomplete activity requires Google Play Services to be available. The intent
        // builder checks this and throws an exception if it is not the case.
        PlaceAutocomplete.IntentBuilder intentBuilder = new PlaceAutocomplete.IntentBuilder(useOverlay ? PlaceAutocomplete.MODE_OVERLAY : PlaceAutocomplete.MODE_FULLSCREEN);
        if (latitude != 0 && longitude != 0 && radius != 0) {
            intentBuilder.setBoundsBias(this.getLatLngBounds(center, radius));
        }
        Intent intent = intentBuilder.setFilter(getFilterType(type, country)).build(currentActivity);
        currentActivity.startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException e) {
        // Indicates that Google Play Services is either not installed or not up to date. Prompt
        // the user to correct the issue.
        GoogleApiAvailability.getInstance().getErrorDialog(currentActivity, e.getConnectionStatusCode(), AUTOCOMPLETE_REQUEST_CODE).show();
    } catch (GooglePlayServicesNotAvailableException e) {
        // Indicates that Google Play Services is not available and the problem is not easily
        // resolvable.
        String message = "Google Play Services is not available: " + GoogleApiAvailability.getInstance().getErrorString(e.errorCode);
        Log.e(TAG, message);
        rejectPromise("E_INTENT_ERROR", new Error("Google Play Services is not available"));
    }
}
Also used : Activity(android.app.Activity) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) PlaceAutocomplete(com.google.android.gms.location.places.ui.PlaceAutocomplete) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 3 with GooglePlayServicesRepairableException

use of com.google.android.gms.common.GooglePlayServicesRepairableException in project grpc-java by grpc.

the class TesterInstrumentation method onCreate.

@Override
public void onCreate(Bundle args) {
    super.onCreate(args);
    testCase = args.getString("test_case") != null ? args.getString("test_case") : "empty_unary";
    host = args.getString("server_host");
    port = Integer.parseInt(args.getString("server_port"));
    serverHostOverride = args.getString("server_host_override");
    useTls = args.getString("use_tls") != null ? Boolean.parseBoolean(args.getString("use_tls")) : true;
    useTestCa = args.getString("use_test_ca") != null ? Boolean.parseBoolean(args.getString("use_test_ca")) : false;
    androidSocketFactoryTls = args.getString("android_socket_factory_tls");
    InputStream testCa = null;
    if (useTestCa) {
        testCa = getContext().getResources().openRawResource(R.raw.ca);
    }
    if (useTls) {
        try {
            ProviderInstaller.installIfNeeded(getContext());
        } catch (GooglePlayServicesRepairableException e) {
            // The provider is helpful, but it is possible to succeed without it.
            // Hope that the system-provided libraries are new enough.
            Log.w(InteropTester.LOG_TAG, "Failed installing security provider", e);
        } catch (GooglePlayServicesNotAvailableException e) {
            // The provider is helpful, but it is possible to succeed without it.
            // Hope that the system-provided libraries are new enough.
            Log.w(InteropTester.LOG_TAG, "Failed installing security provider", e);
        }
    }
    try {
        new InteropTester(testCase, TesterOkHttpChannelBuilder.build(host, port, serverHostOverride, useTls, testCa, androidSocketFactoryTls), new InteropTester.TestListener() {

            @Override
            public void onPreTest() {
            }

            @Override
            public void onPostTest(String result) {
                Bundle bundle = new Bundle();
                bundle.putString("grpc test result", result);
                if (InteropTester.SUCCESS_MESSAGE.equals(result)) {
                    finish(0, bundle);
                } else {
                    finish(1, bundle);
                }
            }
        }).execute();
    } catch (Throwable t) {
        Bundle bundle = new Bundle();
        bundle.putString("Exception encountered", t.toString());
        finish(1, bundle);
    }
}
Also used : InputStream(java.io.InputStream) Bundle(android.os.Bundle) Throwable(java.lang.Throwable) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException)

Example 4 with GooglePlayServicesRepairableException

use of com.google.android.gms.common.GooglePlayServicesRepairableException in project UniPool by divya21raj.

the class NewEntryActivity method showPlaceAutocomplete.

private void showPlaceAutocomplete(int i) {
    try {
        AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder().setTypeFilter(Place.TYPE_COUNTRY).setCountry("IN").build();
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).setFilter(autocompleteFilter).build(this);
        startActivityForResult(intent, i);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        Toast.makeText(this, "Google Play Service Error!", Toast.LENGTH_SHORT).show();
    }
}
Also used : AutocompleteFilter(com.google.android.gms.location.places.AutocompleteFilter) Intent(android.content.Intent) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException)

Example 5 with GooglePlayServicesRepairableException

use of com.google.android.gms.common.GooglePlayServicesRepairableException in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method openPlacePickerModal.

@ReactMethod
public void openPlacePickerModal(ReadableMap options, final Promise promise) {
    this.pendingPromise = promise;
    Activity currentActivity = getCurrentActivity();
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    try {
        PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
        if (latitude != 0 && longitude != 0 && radius != 0) {
            intentBuilder.setLatLngBounds(this.getLatLngBounds(center, radius));
        }
        Intent intent = intentBuilder.build(currentActivity);
        // Start the Intent by requesting a result, identified by a request code.
        currentActivity.startActivityForResult(intent, PLACE_PICKER_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException e) {
        GoogleApiAvailability.getInstance().getErrorDialog(currentActivity, e.getConnectionStatusCode(), PLACE_PICKER_REQUEST_CODE).show();
    } catch (GooglePlayServicesNotAvailableException e) {
        rejectPromise("E_INTENT_ERROR", new Error("Google Play Services is not available"));
    }
}
Also used : PlacePicker(com.google.android.gms.location.places.ui.PlacePicker) Activity(android.app.Activity) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

GooglePlayServicesNotAvailableException (com.google.android.gms.common.GooglePlayServicesNotAvailableException)5 GooglePlayServicesRepairableException (com.google.android.gms.common.GooglePlayServicesRepairableException)5 Intent (android.content.Intent)4 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 ReactMethod (com.facebook.react.bridge.ReactMethod)2 PlacePicker (com.google.android.gms.location.places.ui.PlacePicker)2 LatLng (com.google.android.gms.maps.model.LatLng)2 RESULT_OK (android.app.Activity.RESULT_OK)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 DataBindingUtil (android.databinding.DataBindingUtil)1 Nullable (android.support.annotation.Nullable)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 ActionBar (android.support.v7.app.ActionBar)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 Editable (android.text.Editable)1 TextUtils (android.text.TextUtils)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1