com.google.android.gms.common.GooglePlayServicesUtil Java Examples
The following examples show how to use
com.google.android.gms.common.GooglePlayServicesUtil.
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: MapListActivity.java From android-map_list with MIT License | 6 votes |
@Override protected void onResume() { super.onResume(); int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode == ConnectionResult.SUCCESS) { mRecyclerView.setAdapter(mListAdapter); } else { GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1).show(); } if (mListAdapter != null) { for (MapView m : mListAdapter.getMapViews()) { m.onResume(); } } }
Example #2
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 6 votes |
protected boolean servicesConnected() { // Google Play Servicesが利用可能かどうかチェック int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (ConnectionResult.SUCCESS == resultCode) { // Google Play Servicesが利用可能な場合 return true; } else { // Google Play Servicesが何らかの理由で利用できない場合 // 解決策が書いてあるダイアログが貰えるので、DialogFragmentで表示する showErrorDialog(resultCode, 0); return false; } }
Example #3
Source File: MapsActivity.java From vocefiscal-android with Apache License 2.0 | 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() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { finish(); } return false; } return true; }
Example #4
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_lisence: final String message = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this); new AlertDialog.Builder(this).setTitle(R.string.action_lisence).setMessage(message) .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); break; } return super.onOptionsItemSelected(item); }
Example #5
Source File: LeanbackFragment.java From CumulusTV with MIT License | 6 votes |
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (DEBUG) { Log.d(TAG, "Error connecting " + connectionResult.getErrorCode()); Log.d(TAG, "oCF " + connectionResult.toString()); } if (connectionResult.hasResolution()) { try { connectionResult.startResolutionForResult(mActivity, ActivityUtils.RESOLVE_CONNECTION_REQUEST_CODE); } catch (IntentSender.SendIntentException e) { // Unable to resolve, message user appropriately } } else { GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), mActivity, 0).show(); } }
Example #6
Source File: GacFragment.java From easygoogle with Apache License 2.0 | 6 votes |
private void showErrorDialog(ConnectionResult connectionResult) { int errorCode = connectionResult.getErrorCode(); if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { // Show the default Google Play services error dialog which may still start an intent // on our behalf if the user can resolve the issue. GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), mResolutionCode, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mShouldResolve = false; } }).show(); } else { // No default Google Play Services error, display a message to the user. String errorString = getString(R.string.play_services_error_fmt, errorCode); Toast.makeText(getActivity(), errorString, Toast.LENGTH_SHORT).show(); mShouldResolve = false; } }
Example #7
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 #8
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 #9
Source File: DataCastManager.java From android with Apache License 2.0 | 6 votes |
/** * Initializes the DataCastManager for clients. Before clients can use DataCastManager, they * need to initialize it by calling this static method. Then clients can obtain an instance of * this singleton class by calling {@link DataCastManager#getInstance()}. 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 namespaces to be set up for this class. * @return */ public static DataCastManager initialize(Context context, String applicationId, String... namespaces) { if (null == sInstance) { LOGD(TAG, "New instance of DataCastManager is created"); if (ConnectionResult.SUCCESS != GooglePlayServicesUtil .isGooglePlayServicesAvailable(context)) { String msg = "Couldn't find the appropriate version of Google Play Services"; LOGE(TAG, msg); throw new RuntimeException(msg); } sInstance = new DataCastManager(context, applicationId, namespaces); mCastManager = sInstance; } return sInstance; }
Example #10
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 #11
Source File: TaskListFragment.java From SimplePomodoro-android with MIT License | 6 votes |
/** Check that Google Play services APK is installed and up to date. */ private boolean checkGooglePlayServicesAvailable() { // final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); // if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) { // showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode); // return false; // } // Check status of Google Play Services int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); // Check Google Play Service Available try { if (status != ConnectionResult.SUCCESS) { GooglePlayServicesUtil.getErrorDialog(status, getActivity(), status).show(); } } catch (Exception e) { Log.e("Error: GooglePlayServiceUtil: ", "" + e); } return true; }
Example #12
Source File: ConfigHelper.java From FORMWatchFace with Apache License 2.0 | 6 votes |
public boolean connect() { if (mGoogleApiClient != null) { return true; } if (ConnectionResult.SUCCESS != GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext) || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) { return false; } mGoogleApiClient = new GoogleApiClient.Builder(mContext) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(5, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode()); mGoogleApiClient = null; return false; } return true; }
Example #13
Source File: MapFactory.java From osmdroid with Apache License 2.0 | 6 votes |
/** * Check whether Google Maps v2 is supported on this device. */ public static boolean isGoogleMapsV2Supported(final Context aContext) { try { // first check if Google Play Services is available int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(aContext); if (resultCode == ConnectionResult.SUCCESS) { // then check if OpenGL ES 2.0 is available final ActivityManager activityManager = (ActivityManager) aContext.getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); return configurationInfo.reqGlEsVersion >= 0x20000; } } catch (Throwable e) { } return false; }
Example #14
Source File: Main.java From chess with Apache License 2.0 | 6 votes |
@Override public void onConnectionFailed(final ConnectionResult connectionResult) { if (connectionResult.hasResolution()) { // This problem can be fixed. So let's try to fix it. try { // launch appropriate UI flow (which might, for example, be the // sign-in flow) connectionResult.startResolutionForResult(this, RC_RESOLVE); } catch (IntentSender.SendIntentException e) { // Try connecting again mGoogleApiClient.connect(); } } else { GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show(); } }
Example #15
Source File: GoogleOauth2.java From edx-app-android with Apache License 2.0 | 6 votes |
private void pickUserAccount() { try { String[] accountTypes = new String[]{"com.google"}; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, true, null, null, null, null); if ( activity == null ) return; // check if play-services are installed int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); if (ConnectionResult.SUCCESS == result) { activity.startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT); logger.debug("Launching google account picker ..."); } else { // display user friendly error message logger.debug("Play services are missing ..."); GooglePlayServicesUtil.getErrorDialog(result, activity, 100).show(); } } catch (ActivityNotFoundException ex) { logger.debug("Google-play-services are missing? cannot login by google"); } }
Example #16
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 #17
Source File: ConnectionActivity.java From Android-GSDemo-GoogleMap with MIT License | 6 votes |
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_open: { int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); if(status != ConnectionResult.SUCCESS) { GooglePlayServicesUtil.getErrorDialog(status, this, status); showToast("Cannot run without Google Play, please check!"); } else { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } break; } default: break; } }
Example #18
Source File: SettingsBackup.java From Slide with GNU General Public License v3.0 | 5 votes |
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (connectionResult.hasResolution()) { try { connectionResult.startResolutionForResult(this, 24); } catch (IntentSender.SendIntentException e) { // Unable to resolve, message user appropriately } } else { GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show(); } }
Example #19
Source File: GCMProvider.java From OPFPush with Apache License 2.0 | 5 votes |
@NonNull @Override public AvailabilityResult getAvailabilityResult() { OPFLog.logMethod(); if (!isReceivePermissionDeclared()) { OPFLog.d("com.google.android.c2dm.permission.RECEIVE permission isn't declared"); return new AvailabilityResult(false); } //Need verify that GCM classes present, because dependency provided. try { Class.forName(GOOGLE_CLOUD_MESSAGING_CLASS_NAME); } catch (ClassNotFoundException e) { return new AvailabilityResult(false); } if (super.getAvailabilityResult().isAvailable()) { final int conResult = GooglePlayServicesUtil .isGooglePlayServicesAvailable(getContext()); if (conResult == ConnectionResult.SUCCESS) { return new AvailabilityResult(true); } else { OPFLog.d("Google Play Services not available. Reason: '%s'.", GooglePlayServicesUtil.getErrorString(conResult)); return new AvailabilityResult(conResult); } } return new AvailabilityResult(false); }
Example #20
Source File: DataCastManager.java From UTubeTV with The Unlicense | 5 votes |
/** * Initializes the DataCastManager for clients. Before clients can use DataCastManager, they * need to initialize it by calling this static method. Then clients can obtain an instance of * this singleton class by calling {@link DataCastManager#getInstance()}. 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 namespaces to be set up for this class. * @return */ public static DataCastManager initialize(Context context, String applicationId, String... namespaces) { if (null == sInstance) { CastUtils.LOGD(TAG, "New instance of DataCastManager is created"); if (ConnectionResult.SUCCESS != GooglePlayServicesUtil.isGooglePlayServicesAvailable(context)) { String msg = "Couldn't find the appropriate version of Goolge Play Services"; CastUtils.LOGE(TAG, msg); throw new RuntimeException(msg); } sInstance = new DataCastManager(context, applicationId, namespaces); sCastManager = sInstance; } return sInstance; }
Example #21
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getArguments()でエラーダイアログ生成に必要な引数を修得する int errorCode = getArguments().getInt(ERROR_CODE); // Google Play servicesでエラーダイアログを生成する Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog( errorCode, getActivity(), CONNECTION_FAILURE_RESOLUTION_REQUEST ); return errorDialog; }
Example #22
Source File: MainActivity.java From CalendarQuickStart with MIT License | 5 votes |
/** * Display an error dialog showing that Google Play Services is missing * or out of date. * @param connectionStatusCode code describing the presence (or lack of) * Google Play Services on this device. */ void showGooglePlayServicesAvailabilityErrorDialog( final int connectionStatusCode) { runOnUiThread(new Runnable() { @Override public void run() { Dialog dialog = GooglePlayServicesUtil.getErrorDialog( connectionStatusCode, MainActivity.this, REQUEST_GOOGLE_PLAY_SERVICES); dialog.show(); } }); }
Example #23
Source File: TictactoeActivity.java From appengine-endpoints-tictactoe-android with Apache License 2.0 | 5 votes |
/** * Called if the device does not have Google Play Services installed. */ void showGooglePlayServicesAvailabilityErrorDialog(final int connectionStatusCode) { runOnUiThread(new Runnable() { @Override public void run() { Dialog dialog = GooglePlayServicesUtil.getErrorDialog( connectionStatusCode, TictactoeActivity.this, REQUEST_GOOGLE_PLAY_SERVICES); dialog.show(); } }); }
Example #24
Source File: BaseGameUtils.java From 8bitartist with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example #25
Source File: FirstrunActivity.java From shortyz with GNU General Public License v3.0 | 5 votes |
/** * Display an error dialog showing that Google Play Services is missing * or out of date. * @param connectionStatusCode code describing the presence (or lack of) * Google Play Services on this device. */ void showGooglePlayServicesAvailabilityErrorDialog( final int connectionStatusCode) { runOnUiThread(new Runnable() { @Override public void run() { Dialog dialog = GooglePlayServicesUtil.getErrorDialog( connectionStatusCode, FirstrunActivity.this, GMConstants.REQUEST_GOOGLE_PLAY_SERVICES); dialog.show(); } }); }
Example #26
Source File: MainActivity.java From effective_android_sample with Apache License 2.0 | 5 votes |
/** * エラーダイアログを表示します。 * * @param errorCode * {@link GooglePlayServicesUtil#isGooglePlayServicesAvailable(android.content.Context)}でもらえたコード * @param requestCode * 特に使わない場合は0にします */ protected void showErrorDialog(int errorCode, int requestCode) { // Google Play servicesからエラーダイアログを受け取る Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, this, requestCode); if (errorDialog != null) { ErrorDialogFragment errorFragment = new ErrorDialogFragment(); errorFragment.setDialog(errorDialog); errorFragment.show(getSupportFragmentManager(), ErrorDialogFragment.TAG); } }
Example #27
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 #28
Source File: Game.java From FlappyCow with MIT License | 5 votes |
/** * Resumes the view (but waits the view waits for a tap) * and starts the music if it should be running. * Also checks whether the Google Play Services are available. */ @Override protected void onResume() { view.drawOnce(); if(musicShouldPlay){ musicPlayer.start(); } if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) != ConnectionResult.SUCCESS){ Toast.makeText(this, "Please check your Google Services", Toast.LENGTH_LONG).show(); } super.onResume(); }
Example #29
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 #30
Source File: MainActivity.java From drip-steps with Apache License 2.0 | 5 votes |
@Override public void onConnectionFailed(ConnectionResult result) { if (!result.hasResolution()) { GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), MainActivity.this, 0).show(); return; } if (!authInProgress) { try { authInProgress = true; result.startResolutionForResult(MainActivity.this, REQUEST_OAUTH); } catch (IntentSender.SendIntentException e) { Toast.makeText(MainActivity.this, R.string.connection_failed, Toast.LENGTH_LONG).show(); finish(); } } }