@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(); }
@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 Logout(String params_str) { Log.v(TAG, "Logout(" + params_str + ")"); LoginManager.getInstance().logOut(); UnityMessage message = new UnityMessage("OnLogoutComplete"); message.put("did_complete", true); message.send(); }
private static void addAppLinkToMessage(UnityMessage unityMessage, AppLinkData appLinkData) { if (appLinkData == null) { unityMessage.put("did_complete", true); return; } unityMessage.put("ref", appLinkData.getRef()); unityMessage.put("target_url", appLinkData.getTargetUri().toString()); try { if (appLinkData.getArgumentBundle() != null) { unityMessage.put( "extras", BundleJSONConverter.convertToJSON(appLinkData.getArgumentBundle()).toString()); } } catch (JSONException ex) { Log.e(TAG, ex.getLocalizedMessage()); } }
@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(); } }); }