Java Code Examples for com.google.android.gms.common.GooglePlayServicesUtil#isGooglePlayServicesAvailable()
The following examples show how to use
com.google.android.gms.common.GooglePlayServicesUtil#isGooglePlayServicesAvailable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From MobileShoppingAssistant-sample with Apache License 2.0 | 6 votes |
/** * Checks if Google Play Services are installed and if not it initializes * opening the dialog to allow user to install Google Play Services. * @return a boolean indicating if the Google Play Services are available. */ private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.i(TAG, "This device is not supported."); finish(); } return false; } return true; }
Example 2
Source File: CastUtils.java From UTubeTV with The Unlicense | 6 votes |
/** * A utility method to validate that the appropriate version of the Google Play Services is * available on the device. If not, it will open a dialog to address the issue. The dialog * displays a localized message about the error and upon user confirmation (by tapping on * dialog) will direct them to the Play Store if Google Play services is out of date or missing, * or to system settings if Google Play services is disabled on the device. */ public static boolean checkGooglePlayServices(final Activity activity) { final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); switch (googlePlayServicesCheck) { case ConnectionResult.SUCCESS: return true; default: Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } return false; }
Example 3
Source File: GCMPushPlugin.java From GCMPushPlugin with MIT License | 6 votes |
/** * 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() { final int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(cordova.getActivity()); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { GooglePlayServicesUtil.getErrorDialog(resultCode, cordova.getActivity(), 9000).show(); } }); } else { Log.i(TAG, "This device is not supported."); cordova.getActivity().finish(); } return false; } return true; }
Example 4
Source File: Utils.java From android with Apache License 2.0 | 6 votes |
/** * A utility method to validate that the appropriate version of the Google Play Services is * available on the device. If not, it will open a dialog to address the issue. The dialog * displays a localized message about the error and upon user confirmation (by tapping on * dialog) will direct them to the Play Store if Google Play services is out of date or missing, * or to system settings if Google Play services is disabled on the device. * * @param activity * @return */ public static boolean checkGooglePlayServices(final Activity activity) { final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable( activity); switch (googlePlayServicesCheck) { case ConnectionResult.SUCCESS: return true; default: Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } return false; }
Example 5
Source File: SignInActivity.java From MobileShoppingAssistant-sample with Apache License 2.0 | 6 votes |
/** * Checks if Google Play Services are installed and if not it initializes * opening the dialog to allow user to install Google Play Services. * @return a boolean indicating if the Google Play Services are available. */ private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, MainActivity.PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.i(TAG, "This device is not supported."); finish(); } return false; } return true; }
Example 6
Source File: TrackListActivity.java From mytracks with Apache License 2.0 | 6 votes |
private void checkGooglePlayServices() { int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (code != ConnectionResult.SUCCESS) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog( code, this, GOOGLE_PLAY_SERVICES_REQUEST_CODE, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { finish(); } }); if (dialog != null) { dialog.show(); return; } } }
Example 7
Source File: BaseGameUtils.java From 8bitartist with Apache License 2.0 | 5 votes |
/** * Show a {@link android.app.Dialog} with the correct message for a connection error. * @param activity the Activity in which the Dialog should be displayed. * @param requestCode the request code from onActivityResult. * @param actResp the response code from onActivityResult. * @param errorDescription the resource id of a String for a generic error message. */ public static void showActivityResultError(Activity activity, int requestCode, int actResp, int errorDescription) { if (activity == null) { Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!"); return; } Dialog errorDialog; switch (actResp) { case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED: errorDialog = makeSimpleDialog(activity, activity.getString(R.string.app_misconfigured)); break; case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED: errorDialog = makeSimpleDialog(activity, activity.getString(R.string.sign_in_failed)); break; case GamesActivityResultCodes.RESULT_LICENSE_FAILED: errorDialog = makeSimpleDialog(activity, activity.getString(R.string.license_failed)); break; default: // No meaningful Activity response code, so generate default Google // Play services dialog final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode, null); if (errorDialog == null) { // get fallback dialog Log.e("BaseGamesUtils", "No standard error dialog available. Making fallback dialog."); errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription)); } } errorDialog.show(); }
Example 8
Source File: RMBTMapFragment.java From open-rmbt with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.map_google, container, false); registerListeners(view); if (! myLocationEnabled) view.findViewById(R.id.mapLocateButton).setVisibility(View.INVISIBLE); final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); if (errorCode != ConnectionResult.SUCCESS) { final Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), 0); errorDialog.show(); getFragmentManager().popBackStack(); return view; } View mapView = super.onCreateView(inflater, container, savedInstanceState); final RelativeLayout mapViewContainer = (RelativeLayout) view.findViewById(R.id.mapViewContainer); mapViewContainer.addView(mapView); ProgressBar progessBar = new ProgressBar(getActivity()); final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1); progessBar.setLayoutParams(layoutParams); progessBar.setVisibility(View.GONE); view.addView(progessBar); return view; }
Example 9
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 5 votes |
private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.i(TAG, "Playサービスがサポートされていない端末です"); finish(); } return false; } return true; }
Example 10
Source File: GooglePlayClientWrapper.java From barterli_android with Apache License 2.0 | 5 votes |
private boolean servicesConnected() { // Check that Google Play services is available final int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mActivity); // If Google Play services is available if (ConnectionResult.SUCCESS == resultCode) { // In debug mode, log the status Logger.d("Location Updates", "Google Play services is available."); // Continue return true; // Google Play services was not available for some reason } else { if (mConnectionResult != null) { // Get the error code final int errorCode = mConnectionResult.getErrorCode(); // Get the error dialog from Google Play services final Dialog errorDialog = GooglePlayServicesUtil .getErrorDialog(errorCode, mActivity, CONNECTION_FAILURE_RESOLUTION_REQUEST); // If Google Play services can provide an error dialog if (errorDialog != null) { // Create a new DialogFragment for the error dialog final ErrorDialogFragment errorFragment = new ErrorDialogFragment(); // Set the dialog in the DialogFragment errorFragment.setDialog(errorDialog); // Show the error dialog in the DialogFragment errorFragment.show(mActivity.getSupportFragmentManager(), "Location Updates"); } } return false; } }
Example 11
Source File: ApplicationLoader.java From Telegram with GNU General Public License v2.0 | 5 votes |
private boolean checkPlayServices() { try { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); return resultCode == ConnectionResult.SUCCESS; } catch (Exception e) { FileLog.e(e); } return true; }
Example 12
Source File: MainActivity.java From android-Geofencing with Apache License 2.0 | 5 votes |
/** * Checks if Google Play services is available. * @return true if it is. */ private boolean isGooglePlayServicesAvailable() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (ConnectionResult.SUCCESS == resultCode) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Google Play services is available."); } return true; } else { Log.e(TAG, "Google Play services is unavailable."); return false; } }
Example 13
Source File: Utils.java From conference-central-android-app with GNU General Public License v2.0 | 5 votes |
/** * Check that Google Play services APK is installed and up to date. */ public static boolean checkGooglePlayServicesAvailable(Activity activity) { final int connectionStatusCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(activity); if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) { showGooglePlayServicesAvailabilityErrorDialog(activity, connectionStatusCode); return false; } return true; }
Example 14
Source File: SignInActivity.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mShouldFinishOnStop = false; setContentView(R.layout.activity_sign_in); activityComponent().inject(this); ButterKnife.bind(this); mSignInPresenter.attachView(this); setSignInButtonEnabled(false); int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode == ConnectionResult.SUCCESS) { setSignInButtonEnabled(true); } else if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil .getErrorDialog(resultCode, this, REQUEST_CODE_PLAY_SERVICES) .show(); } else { showNoPlayServicesError(); Timber.e("This device doesn't support Play Services"); } String popUpMessage = getIntent().getStringExtra(EXTRA_POPUP_MESSAGE); if (popUpMessage != null) { DialogFactory.createSimpleOkErrorDialog(this, popUpMessage).show(); } }
Example 15
Source File: DriverHome.java From UberClone with MIT License | 5 votes |
private boolean checkPlayServices() { int resultCode= GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode!=ConnectionResult.SUCCESS){ if(GooglePlayServicesUtil.isUserRecoverableError(resultCode)) GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_REQUEST_CODE).show(); else { Message.messageError(this, Errors.NOT_SUPPORT); finish(); } return false; } return true; }
Example 16
Source File: ControllerActivity.java From Bluefruit_LE_Connect_Android with MIT License | 5 votes |
@Override public void onResume() { Log.d(TAG, "onResume"); super.onResume(); int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode == ConnectionResult.SERVICE_MISSING || resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || resultCode == ConnectionResult.SERVICE_DISABLED) { Dialog googlePlayErrorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0); if (googlePlayErrorDialog != null) { googlePlayErrorDialog.show(); } } // Setup listeners mBleManager.setBleListener(this); registerEnabledSensorListeners(true); // Setup send data task if (!isSensorPollingEnabled) { sendDataHandler.postDelayed(mPeriodicallySendData, kSendDataInterval); isSensorPollingEnabled = true; } }
Example 17
Source File: AptoideUtils.java From aptoide-client with GNU General Public License v2.0 | 4 votes |
public static boolean checkGooglePlayServices(Context context) { return GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS; }
Example 18
Source File: DefaultAirMapViewBuilder.java From AirMapView with Apache License 2.0 | 4 votes |
private static boolean isGooglePlayServicesAvailable(Context context) { return GooglePlayServicesUtil. isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS; }
Example 19
Source File: LocationController.java From slidingdebugmenu with Apache License 2.0 | 4 votes |
private LocationController(Context context) { if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) mLocationClient = new LocationClient(context, this, this); else EventBus.getDefault().post(new LocationEvent(null)); }
Example 20
Source File: VideoCastManager.java From android with Apache License 2.0 | 3 votes |
/** * Initializes the VideoCastManager for clients. Before clients can use VideoCastManager, they * need to initialize it by calling this static method. Then clients can obtain an instance of * this singleton class by calling {@link getInstance()} or {@link getInstance(Context)}. * Failing to initialize this class before requesting an instance will result in a * {@link CastException} exception. * * @param context * @param applicationId the unique ID for your application * @param targetActivity this points to the activity that should be invoked when user clicks on * the icon in the {@link MiniController}. Often this is the activity that hosts the local * player. * @param dataNamespace if not <code>null</code>, a custom data channel with this namespace * will be created. * @return * @see getInstance() */ public static synchronized VideoCastManager initialize(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) { if (null == sInstance) { LOGD(TAG, "New instance of VideoCastManager is created"); if (ConnectionResult.SUCCESS != GooglePlayServicesUtil .isGooglePlayServicesAvailable(context)) { String msg = "Couldn't find the appropriate version of Goolge Play Services"; LOGE(TAG, msg); } sInstance = new VideoCastManager(context, applicationId, targetActivity, dataNamespace); mCastManager = sInstance; } return sInstance; }