Пример #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();
  }
Пример #2
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();
          }
        });
  }
Пример #3
0
 private static void startActivity(Class<?> cls, String paramsStr) {
   Intent intent = new Intent(getUnityActivity(), cls);
   UnityParams unityParams = UnityParams.parse(paramsStr);
   Bundle params = unityParams.getStringParams();
   intent.putExtra(BaseActivity.ACTIVITY_PARAMS, params);
   getUnityActivity().startActivity(intent);
 }
Пример #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();
          }
        });
  }
Пример #5
0
 @UnityCallable
 public static void AppInvite(String paramsStr) {
   Log.v(TAG, "AppInvite(" + paramsStr + ")");
   Intent intent = new Intent(getUnityActivity(), AppInviteDialogActivity.class);
   UnityParams unityParams = UnityParams.parse(paramsStr);
   Bundle params = unityParams.getStringParams();
   intent.putExtra(AppInviteDialogActivity.DIALOG_PARAMS, params);
   getUnityActivity().startActivity(intent);
 }
Пример #6
0
 @UnityCallable
 public static void GameGroupJoin(String params_str) {
   Log.v(TAG, "GameGroupJoin(" + params_str + ")");
   final UnityParams unity_params = UnityParams.parse(params_str);
   final Bundle params = unity_params.getStringParams();
   Intent intent = new Intent(getUnityActivity(), FBUnityJoinGameGroupActivity.class);
   intent.putExtra(FBUnityJoinGameGroupActivity.JOIN_GAME_GROUP_PARAMS, params);
   getUnityActivity().startActivity(intent);
 }
Пример #7
0
 @UnityCallable
 public static void AppRequest(String params_str) {
   Log.v(TAG, "AppRequest(" + params_str + ")");
   Intent intent = new Intent(getUnityActivity(), FBUnityGameRequestActivity.class);
   UnityParams unity_params = UnityParams.parse(params_str);
   Bundle params = unity_params.getStringParams();
   intent.putExtra(FBUnityGameRequestActivity.GAME_REQUEST_PARAMS, params);
   getUnityActivity().startActivity(intent);
 }
Пример #8
0
 @UnityCallable
 public static void FeedShare(String params_str) {
   Log.v(TAG, "FeedShare(" + params_str + ")");
   final UnityParams unityParams = UnityParams.parse(params_str);
   final Bundle params = unityParams.getStringParams();
   Intent intent = new Intent(getUnityActivity(), FBUnityDialogsActivity.class);
   intent.putExtra(FBUnityDialogsActivity.DIALOG_TYPE, ShareDialog.Mode.FEED);
   intent.putExtra(FBUnityDialogsActivity.FEED_DIALOG_PARAMS, params);
   getUnityActivity().startActivity(intent);
 }
Пример #9
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();
          }
        });
  }
Пример #10
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);
    }
  }