com.google.android.gms.common.api.Status.hasResolution()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.google.android.gms.common.api.Status.hasResolution()方法的一些代码示例,展示了Status.hasResolution()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.hasResolution()方法的具体详情如下:
包路径:com.google.android.gms.common.api.Status
类名称:Status
方法名:hasResolution

Status.hasResolution介绍

[英]Returns true if calling #startResolutionForResult(Activity,int) will start any intents requiring user interaction.
[中]如果调用#startResolutionForResult(Activity,int)将启动任何需要用户交互的意图,则返回true。

代码示例

代码示例来源:origin: ShlMlkzdh/RxSmartLock

@Override
public void onError(Throwable e) {
  if (e instanceof StatusException) {
    Status status = ((StatusException) e).getStatus();
    if (status.hasResolution()) {
      try {
        status.startResolutionForResult(MainActivity.this, CREDENTIAL_REQUEST_RC);
      } catch (IntentSender.SendIntentException e1) {
        Log.e(TAG, "STATUS: Failed to send resolution.");
      }
    } else {
      // The user must create an account or sign in manually.
      Log.e(TAG, "STATUS: Unsuccessful credential request.");
    }
  }
}

代码示例来源:origin: microg/android_external_GmsApi

/**
 * Resolves an error by starting any intents requiring user interaction. See
 * {@link CommonStatusCodes#SIGN_IN_REQUIRED}, and {@link CommonStatusCodes#RESOLUTION_REQUIRED}.
 *
 * @param activity    An Activity context to use to resolve the issue. The activity's
 *                    onActivityResult method will be invoked after the user is done. If the
 *                    resultCode is {@link Activity#RESULT_OK}, the application should try to
 *                    connect again.
 * @param requestCode The request code to pass to onActivityResult.
 * @throws SendIntentException If the resolution intent has been canceled or is no longer able
 *                             to execute the request.
 */
public void startResolutionForResult(Activity activity, int requestCode) throws SendIntentException {
  if (hasResolution()) {
    activity.startIntentSenderForResult(resolution.getIntentSender(), requestCode, null, 0, 0, 0);
  }
}

代码示例来源:origin: Michenux/YourAppIdea

public void onResult(Status status) {
    if (status.isSuccess()) {
      // Successfully registered
    } else if (status.hasResolution()) {
      // Google provides a way to fix the issue
      try {
        status.startResolutionForResult(
            AroundMeFragment.this.getActivity(),     // your current activity used to receive the result
            LOCATIONSERVICES_RESOLUTION_RESULCODE); // the result code you'll look for in your onActivityResult method to retry registering
      } catch (IntentSender.SendIntentException e) {
        Log.e(YourApplication.LOG_TAG, "SimpleMapFragment start resolution failure: ", e);
      }
    } else {
      // No recovery. Weep softly or inform the user.
      Log.e(YourApplication.LOG_TAG, "SimpleMapFragment registering failed: " + status.getStatusMessage());
    }
  }
});

代码示例来源:origin: florent37/RxGps

public static <R extends Result> ObservableTransformer<R, R> forObservable() {
  return upstream -> upstream.onErrorResumeNext(throwable -> {
    if(throwable instanceof StatusException) {
      StatusException statusException = (StatusException) throwable;
      if(statusException.getStatus().hasResolution()) {
        return Observable.just((R) statusException.getResult());
      } else {
        return Observable.error(throwable);
      }
    } else {
      return Observable.error(throwable);
    }
  });
}

代码示例来源:origin: Michenux/YourAppIdea

@SuppressWarnings({"MissingPermission"})
private void registerLocationUpdates() {
  PendingResult<Status> result = LocationServices.FusedLocationApi
      .requestLocationUpdates(
          mGoogleApiClient,
          mRequest,
          this);
  result.setResultCallback(status -> {
    if (status.isSuccess()) {
      // Successfully registered
    } else if (status.hasResolution()) {
      // Google provides a way to fix the issue
      try {
        status.startResolutionForResult(
            SimpleMapFragment.this.getActivity(),     // your current activity used to receive the result
            LOCATIONSERVICES_RESOLUTION_RESULCODE); // the result code you'll look for in your onActivityResult method to retry registering
      } catch (IntentSender.SendIntentException e) {
        Log.e(YourApplication.LOG_TAG, "SimpleMapFragment start resolution failure: ", e);
      }
    } else {
      // No recovery. Weep softly or inform the user.
      Log.e(YourApplication.LOG_TAG, "SimpleMapFragment registering failed: " + status.getStatusMessage());
    }
  });
}

代码示例来源:origin: dsolonenko/financisto

@Subscribe(threadMode = ThreadMode.MAIN)
public void onDriveBackupFailed(DriveBackupFailure event) {
  dismissProgressDialog();
  Status status = event.status;
  if (status.hasResolution()) {
    try {
      status.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
    } catch (IntentSender.SendIntentException e) {
      // Unable to resolve, message user appropriately
      onDriveBackupError(new DriveBackupError(e.getMessage()));
    }
  } else {
    GooglePlayServicesUtil.getErrorDialog(status.getStatusCode(), this, 0).show();
  }
}

代码示例来源:origin: florent37/RxGps

public static <R extends Result> FlowableTransformer<R, R> forFlowable() {
  return upstream -> upstream.onErrorResumeNext(throwable -> {
    if(throwable instanceof StatusException) {
      StatusException statusException = (StatusException) throwable;
      if(statusException.getStatus().hasResolution()) {
        return Flowable.just((R) statusException.getResult());
      } else {
        return Flowable.error(throwable);
      }
    } else {
      return Flowable.error(throwable);
    }
  });
}

代码示例来源:origin: florent37/RxGps

public static <R extends Result> SingleTransformer<R, R> forSingle() {
    return upstream -> upstream.onErrorResumeNext(throwable -> {
      if(throwable instanceof StatusException) {
        StatusException statusException = (StatusException) throwable;

        if(statusException.getStatus().hasResolution()) {
          return Single.just((R) statusException.getResult());
        } else {
          return Single.error(throwable);
        }

      } else {
        return Single.error(throwable);
      }
    });
  }
}

代码示例来源:origin: Michenux/YourAppIdea

private void handleSignInResult(GoogleSignInResult result) {
  if (BuildConfig.DEBUG) {
    Log.d(MCXApplication.LOG_TAG, "handleSignInResult:" + result.isSuccess() + " " + result.getStatus().getStatusCode() +
        result.getStatus().hasResolution());
  }
  if (result.isSuccess()) {
    // Signed in successfully, show authenticated UI.
    GoogleSignInAccount acct = result.getSignInAccount();
    User user = new User();
    user.setProvider(PROVIDER_NAME);
    user.setProviderDisplayName("Google+");
    user.setUserId(acct.getId());
    user.setUserName(acct.getId());
    user.setDisplayName(acct.getDisplayName());
    user.setMail(acct.getEmail());
    this.mUserHelper.setCurrentUser(user);
    if (this.mUserSessionCallback != null) {
      this.mUserSessionCallback.onLogin();
    }
  } else {
    // Signed out, show unauthenticated UI.
    this.mUserSessionCallback.onLogout();
  }
}

相关文章