本文整理汇总了Java中com.google.android.gms.common.GooglePlayServicesUtil类的典型用法代码示例。如果您正苦于以下问题:Java GooglePlayServicesUtil类的具体用法?Java GooglePlayServicesUtil怎么用?Java GooglePlayServicesUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GooglePlayServicesUtil类属于com.google.android.gms.common包,在下文中一共展示了GooglePlayServicesUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPlayServices
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(
resultCode, this, REQUEST_CODE_PLAY_SERVICES).show();
} else {
Dialog playServicesDialog = DialogFactory.createSimpleOkErrorDialog(
this,
getString(R.string.dialog_error_title),
getString(R.string.error_message_play_services)
);
playServicesDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
});
playServicesDialog.show();
}
return false;
}
return true;
}
示例2: checkGooglePlayServices
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
public static boolean checkGooglePlayServices(final Activity activity) {
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
switch (googlePlayServicesCheck) {
case ConnectionResult.SUCCESS:
return true;
case ConnectionResult.SERVICE_DISABLED:
case ConnectionResult.SERVICE_INVALID:
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
activity.finish();
}
});
dialog.show();
}
return false;
}
示例3: checkPlayServices
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private boolean checkPlayServices()
{
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
if (resultCode != ConnectionResult.SUCCESS)
{
//if (GooglePlayServicesUtil.isUserRecoverableError(resultCode))
//{
// GooglePlayServicesUtil.getErrorDialog(resultCode, mContext, PLAY_SERVICES_RESOLUTION_REQUEST).show();
//} else {
// Log.i(TAG, "This device is not supported.");
//}
Log.i("yoyo", "!Google play not found on device");
return false;
}
return true;
}
示例4: onRun
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
@Override
public void onRun() throws Exception {
if (TextSecurePreferences.isGcmDisabled(context)) return;
Log.w(TAG, "Reregistering GCM...");
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (result != ConnectionResult.SUCCESS) {
notifyGcmFailure();
} else {
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
textSecureAccountManager.setGcmId(Optional.of(gcmId));
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
TextSecurePreferences.setWebsocketRegistered(context, true);
}
}
示例5: checkPlayServices
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private boolean checkPlayServices() {
try {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
return resultCode == ConnectionResult.SUCCESS;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return true;
/*if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i("tmessages", "This device is not supported.");
}
return false;
}
return true;*/
}
示例6: resolveConnectionFailure
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
/**
* 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,
int 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, activity.getString(fallbackErrorMessage));
}
return false;
}
}
示例7: showRecoveryDialog
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private void showRecoveryDialog(int statusCode) {
Activity activity = getActivity("showRecoveryDialog()");
if (activity == null) {
return;
}
if (sCanShowAuthUi) {
sCanShowAuthUi = false;
LOGD(TAG, "Showing recovery dialog for status code " + statusCode);
final Dialog d = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, REQUEST_RECOVER_FROM_PLAY_SERVICES_ERROR);
d.show();
} else {
LOGD(TAG, "Not showing Play Services recovery dialog because sCanShowSignInUi==false.");
reportAuthFailure();
}
}
示例8: isGoogleplayServicesAvailableNoDialogs
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private boolean isGoogleplayServicesAvailableNoDialogs() {
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getActivity()
.getApplicationContext());
switch (resultCode) {
case SUCCESS:
return true;
case SERVICE_DISABLED:
return false;
case SERVICE_MISSING:
return false;
case SERVICE_VERSION_UPDATE_REQUIRED:
return false;
case CANCELED:
return false;
}
return false;
}
示例9: checkGooglePlayServices
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
/**
* 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;
}
示例10: servicesConnected
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private boolean servicesConnected() {
// Check that Google Play services is available
int resultCode =
GooglePlayServicesUtil.
isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d("LocationUpdates",
"Google Play services is available.");
// Continue
return true;
// Google Play services was not available for some reason
} else {
Log.e("LocationUpdates",
"Google Play services is not available.");
}
return false;
}
示例11: onResume
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (errorCode != ConnectionResult.SUCCESS) {
Dialog errorDialog = GooglePlayServicesUtil
.getErrorDialog(errorCode, this, REQUEST_ERROR,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// Leave if services are unavailable.
finish();
}
});
errorDialog.show();
}
}
示例12: showActivityResultError
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
/**
* 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();
}
示例13: handleAuthException
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
private void handleAuthException(final Activity activity, final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
// Unable to authenticate, such as when the user has not yet granted
// the app access to the account, but the user can fix this.
// Forward the user to an activity in Google Play services.
Intent intent = ((UserRecoverableAuthException) e).getIntent();
activity.startActivityForResult(
intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
}
}
});
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:25,代码来源:AuthTaskUrlShortener.java
示例14: handleAuthException
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
public static void handleAuthException(final Activity activity, final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException)e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, Constants.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
}
else if (e instanceof UserRecoverableAuthException) {
// Unable to authenticate, such as when the user has not yet granted
// the app access to the account, but the user can fix this.
// Forward the user to an activity in Google Play services.
Intent intent = ((UserRecoverableAuthException)e).getIntent();
activity.startActivityForResult(
intent, Constants.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
}
});
}
示例15: connectPlusClient
import com.google.android.gms.common.GooglePlayServicesUtil; //导入依赖的package包/类
public void connectPlusClient() {
int val = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (val == ConnectionResult.SUCCESS) {
if(!mPlusClient.isConnected()) {
if (mConnectionResult == null) {
mPlusClient.connect();
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (IntentSender.SendIntentException e) {
// Try connecting again.
mConnectionResult = null;
mPlusClient.connect();
}
}
}
} else {
Toast.makeText(this, getString(R.string.google_login_message_play_services_not_available), Toast.LENGTH_SHORT).show();
}
}