@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(); } }); }
@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(); } }); }
@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); } }
@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(); } }); }