本文整理汇总了Java中com.google.android.gms.common.ConnectionResult.getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionResult.getErrorCode方法的具体用法?Java ConnectionResult.getErrorCode怎么用?Java ConnectionResult.getErrorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.common.ConnectionResult
的用法示例。
在下文中一共展示了ConnectionResult.getErrorCode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveConnectionFailure
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的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;
}
}
示例2: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
try {
String message = getString(R.string.error_056);
if (connectionResult.getErrorMessage() != null && connectionResult.getErrorMessage().length() > 0)
message = connectionResult.getErrorMessage();
else if (connectionResult.getErrorCode() == ConnectionResult.SIGN_IN_REQUIRED) {
message = getString(R.string.error_121);
}
else if (connectionResult.getErrorCode() == ConnectionResult.SIGN_IN_FAILED) {
message = getString(R.string.error_122);
}
AndiCarNotification.showGeneralNotification(this, AndiCarNotification.NOTIFICATION_TYPE_NOT_REPORTABLE_ERROR,
(int) System.currentTimeMillis(), getString(R.string.pref_category_secure_backup), message, null, null);
if (debugLogFileWriter != null) {
debugLogFileWriter.appendnl("Connection failed: ").append(message);
debugLogFileWriter.flush();
}
} catch (IOException e2) {
e2.printStackTrace();
}
}
示例3: resolveConnectionFailure
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的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,
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;
}
}
示例4: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (result.getErrorCode() == SERVICE_MISSING){
showMessage("Google Drive API not Found on this Device");
Log.e(TAG, "Google Drive SERVICE_MISSING");
}
if (result.getErrorCode() == SERVICE_VERSION_UPDATE_REQUIRED){
showMessage("Google Play Services update required. Please update in Google Play store.");
Log.e(TAG, "Google Play Services update required");
mGoogleApiClient.getContext().startActivity(new Intent(mGoogleApiClient.getContext(), MainActivity.class)
.putExtra("PlayServicesUpdate", true).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
PendingIntent pI = result.getResolution();
if (pI != null) {
Log.v(TAG, "PendingIntent: " + pI.getIntentSender().toString());
mGoogleApiClient.getContext().startActivity(new Intent(mGoogleApiClient.getContext(), MainActivity.class)
.putExtra("resolution", pI).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
Log.e(TAG, "Pending Intent resolution was Null");
}
// If we don't stop this service, we tend to have an invalid API client
// when we call the first Create new Drive file command
stopSelf(mStartID);
}
示例5: resolveConnectionFailure
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的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,
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;
}
}
示例6: resolveConnectionFailure
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
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;
}
}
示例7: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
ToastLog.warnShort(context, TAG, "Google API failed.");
switch (connectionResult.getErrorCode()) {
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: // SERVICE_VERSION_UPDATE_REQUIRED
break;
}
}
示例8: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// ConnectionResult參數是連線失敗的資訊
int errorCode = connectionResult.getErrorCode();
// 裝置沒有安裝Google Play服務
if (errorCode == ConnectionResult.SERVICE_MISSING) {
Toast.makeText(this, R.string.google_play_service_missing, Toast.LENGTH_LONG).show();
}
}
示例9: resolveConnectionFailure
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的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;
}
}
示例10: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Activity activity = getActivity("onConnectionFailed()");
if (activity == null) {
return;
}
if (connectionResult.hasResolution()) {
if (sCanShowSignInUi) {
LOGD(TAG, "onConnectionFailed, with resolution. Attempting to resolve.");
sCanShowSignInUi = false;
try {
mResolving = true;
connectionResult.startResolutionForResult(activity,
REQUEST_RECOVER_FROM_PLAY_SERVICES_ERROR);
} catch (IntentSender.SendIntentException e) {
LOGE(TAG, "SendIntentException occurred: " + e.getMessage());
e.printStackTrace();
}
} else {
LOGD(TAG, "onConnectionFailed with resolution but sCanShowSignInUi==false.");
reportAuthFailure();
}
return;
}
LOGD(TAG, "onConnectionFailed, no resolution.");
final int errorCode = connectionResult.getErrorCode();
if (GooglePlayServicesUtil.isUserRecoverableError(errorCode) && sCanShowSignInUi) {
sCanShowSignInUi = false;
GooglePlayServicesUtil.getErrorDialog(errorCode, activity,
REQUEST_PLAY_SERVICES_ERROR_DIALOG).show();
} else {
reportAuthFailure();
}
}
示例11: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e(TAG, "onConnectionFailed(): " + connectionResult);
if(connectionResult.getErrorCode() == ConnectionResult.API_UNAVAILABLE) {
mConnectionTitle.setText("Connection Failed");
setConnectionMessage(NO_DEVICES_LINKED);
updateDeviceWearConnectionIcon(R.drawable.avd_device_wear_connection_faliure);
mWearAppButton.setVisibility(View.VISIBLE);
}
}
示例12: onConnectionFailed
import com.google.android.gms.common.ConnectionResult; //导入方法依赖的package包/类
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (mResolvingConnectionFailure) {
// already resolving
return;
}
Gdx.app.log(GAMESERVICE_ID, "onConnectFailed: " + connectionResult.getErrorCode());
boolean isPendingBefore = isConnectionPending;
// if the sign-in button was clicked
// launch the sign-in flow
if (mSignInClicked) {
mAutoStartSignInflow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
// Attempt to resolve the connection failure using BaseGameUtils.
// The R.string.signin_other_error value should reference a generic
// error string in your strings.xml file, such as "There was
// an issue with sign-in, please try again later."
if (!BaseGameUtils.resolveConnectionFailure(myContext,
mGoogleApiClient, connectionResult,
RC_GPGS_SIGNIN, "Unable to sign in.")) {
mResolvingConnectionFailure = false;
isConnectionPending = false;
}
}
// Error code 4 is thrown sometimes on first attempt when game state feature is enabled.
// Just retry some times solves the problem.
else if (firstConnectAttempt > 0 && connectionResult.getErrorCode() == 4) {
firstConnectAttempt -= 1;
Gdx.app.log(GAMESERVICE_ID, "Retrying to connect...");
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
// wait some time before next try
Thread.sleep(200);
if (!mGoogleApiClient.isConnected())
mGoogleApiClient.connect();
} catch (InterruptedException e) {
//eat
}
return null;
}
};
task.execute();
} else
isConnectionPending = false;
// inform listener that connection attempt failed
if (gameListener != null && isPendingBefore && !isConnectionPending)
gameListener.gsOnSessionInactive();
}