コード例 #1
0
  /**
   * Generate a UI dialog for the request action in the given Android context with the provided
   * parameters.
   *
   * <p>Note that this method is asynchronous and the callback will be invoked in the original
   * calling thread (not in a background thread).
   *
   * @param context The Android context in which we will generate this dialog.
   * @param action String representation of the desired method: e.g. "feed" ...
   * @param parameters String key-value pairs to be passed as URL parameters.
   * @param listener Callback interface to notify the application when the dialog has completed.
   */
  public void dialog(
      Context context, String action, Bundle parameters, final DialogListener listener) {

    String endpoint = DIALOG_BASE_URL + action;
    parameters.putString("display", "touch");
    parameters.putString("redirect_uri", REDIRECT_URI);

    if (action.equals(LOGIN)) {
      parameters.putString("type", "user_agent");
      parameters.putString("client_id", mAppId);
    } else {
      parameters.putString("app_id", mAppId);
    }

    if (isSessionValid()) {
      parameters.putString(TOKEN, getAccessToken());
    }
    String url = endpoint + "?" + Util.encodeUrl(parameters);
    if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
        != PackageManager.PERMISSION_GRANTED) {
      Util.showAlert(context, "Error", "Application requires permission to access the Internet");
    } else {
      new FbDialog(context, url, listener).show();
    }
  }