Ejemplo n.º 1
1
  @UnityCallable
  public static void GetAppLink(String paramsStr) {
    Log.v(TAG, "GetAppLink(" + paramsStr + ")");
    final UnityParams unityParams = UnityParams.parse(paramsStr);
    UnityMessage unityMessage =
        UnityMessage.createWithCallbackFromParams("OnGetAppLinkComplete", unityParams);

    // If we don't have an intent return
    if (intent == null) {
      unityMessage.put("did_complete", true);
      unityMessage.send();
      return;
    }

    // Check to see if we have any app link data on the intent
    AppLinkData appLinkData = AppLinkData.createFromAlApplinkData(intent);
    if (appLinkData != null) {
      // We have an app link
      FB.addAppLinkToMessage(unityMessage, appLinkData);
      unityMessage.put("url", intent.getDataString());
    } else if (intent.getData() != null) {
      // We have a deep link
      unityMessage.put("url", intent.getDataString());
    } else {
      // No deep link or app link was provided when activity was started
      unityMessage.put("did_complete", true);
    }

    unityMessage.send();
  }
Ejemplo n.º 2
0
  @UnityCallable
  public static void LogAppEvent(String params_str) {
    Log.v(TAG, "LogAppEvent(" + params_str + ")");
    UnityParams unity_params = UnityParams.parse(params_str);

    Bundle parameters = new Bundle();
    if (unity_params.has("parameters")) {
      UnityParams unity_params_parameter = unity_params.getParamsObject("parameters");
      parameters = unity_params_parameter.getStringParams();
    }

    if (unity_params.has("logPurchase")) {
      FB.getAppEventsLogger()
          .logPurchase(
              new BigDecimal(unity_params.getDouble("logPurchase")),
              Currency.getInstance(unity_params.getString("currency")),
              parameters);
    } else if (unity_params.hasString("logEvent")) {
      if (unity_params.has("valueToSum")) {
        FB.getAppEventsLogger()
            .logEvent(
                unity_params.getString("logEvent"),
                unity_params.getDouble("valueToSum"),
                parameters);
      } else {
        FB.getAppEventsLogger().logEvent(unity_params.getString("logEvent"), parameters);
      }
    } else {
      Log.e(TAG, "couldn't logPurchase or logEvent params: " + params_str);
    }
  }
Ejemplo n.º 3
0
  @UnityCallable
  public static void Init(final String params_str) {
    Log.v(TAG, "Init(" + params_str + ")");
    UnityParams unity_params =
        UnityParams.parse(params_str, "couldn't parse init params: " + params_str);
    final String appID;
    if (unity_params.hasString("appId")) {
      appID = unity_params.getString("appId");
    } else {
      appID = Utility.getMetadataApplicationId(getUnityActivity());
    }

    FacebookSdk.setApplicationId(appID);
    FacebookSdk.sdkInitialize(
        FB.getUnityActivity(),
        new FacebookSdk.InitializeCallback() {
          @Override
          public void onInitialized() {
            final UnityMessage unityMessage = new UnityMessage("OnInitComplete");
            // If we have a cached access token send it back as well
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
              FBLogin.addLoginParametersToMessage(unityMessage, token, null);
            } else {
              unityMessage.put("key_hash", FB.getKeyHash());
            }

            FB.ActivateApp(appID);

            unityMessage.send();
          }
        });
  }
Ejemplo n.º 4
0
  @UnityCallable
  public static void RefreshCurrentAccessToken(String paramsStr) {
    FB.LogMethodCall("RefreshCurrentAccessToken", paramsStr);

    UnityParams unityParams = UnityParams.parse(paramsStr);
    final UnityMessage unityMessage = new UnityMessage("OnRefreshCurrentAccessTokenComplete");
    if (unityParams.hasString("callback_id")) {
      unityMessage.put("callback_id", unityParams.getString("callback_id"));
    }

    AccessToken.refreshCurrentAccessTokenAsync(
        new AccessToken.AccessTokenRefreshCallback() {
          @Override
          public void OnTokenRefreshed(AccessToken accessToken) {
            FBLogin.addLoginParametersToMessage(unityMessage, accessToken, null);
            unityMessage.send();
          }

          @Override
          public void OnTokenRefreshFailed(FacebookException e) {
            unityMessage.sendError(e.getMessage());
          }
        });

    AppLinkData.fetchDeferredAppLinkData(
        getUnityActivity(),
        new AppLinkData.CompletionHandler() {
          @Override
          public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
            FB.addAppLinkToMessage(unityMessage, appLinkData);
            unityMessage.send();
          }
        });
  }
Ejemplo n.º 5
0
  @UnityCallable
  public static void FetchDeferredAppLinkData(String paramsStr) {
    FB.LogMethodCall("FetchDeferredAppLinkData", paramsStr);

    UnityParams unityParams = UnityParams.parse(paramsStr);
    final UnityMessage unityMessage = new UnityMessage("OnFetchDeferredAppLinkComplete");
    if (unityParams.hasString("callback_id")) {
      unityMessage.put("callback_id", unityParams.getString("callback_id"));
    }

    AppLinkData.fetchDeferredAppLinkData(
        getUnityActivity(),
        new AppLinkData.CompletionHandler() {
          @Override
          public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
            FB.addAppLinkToMessage(unityMessage, appLinkData);
            unityMessage.send();
          }
        });
  }