/** * This function initializes the Facebook SDK, the behavior of Facebook SDK functions are * undetermined if this function is not called. It should be called as early as possible. * @param applicationContext The application context */ public static synchronized void sdkInitialize(Context applicationContext) { if (sdkInitialized == true) { return; } Validate.notNull(applicationContext, "applicationContext"); FacebookSdk.applicationContext = applicationContext.getApplicationContext(); // Make sure we've loaded default settings if we haven't already. FacebookSdk.loadDefaultsFromMetadata(FacebookSdk.applicationContext); // Load app settings from network so that dialog configs are available Utility.loadAppSettingsAsync(FacebookSdk.applicationContext, applicationId); BoltsMeasurementEventListener.getInstance(FacebookSdk.applicationContext); cacheDir = FacebookSdk.applicationContext.getCacheDir(); FutureTask<Void> accessTokenLoadFutureTask = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws Exception { AccessTokenManager.getInstance().loadCurrentAccessToken(); ProfileManager.getInstance().loadCurrentProfile(); if (AccessToken.getCurrentAccessToken() != null && Profile.getCurrentProfile() == null) { // Access token and profile went out of sync due to a network or caching // issue, retry Profile.fetchProfileForCurrentAccessToken(); } return null; } }); Executors.newSingleThreadExecutor().execute(accessTokenLoadFutureTask); sdkInitialized = true; }
/** * This function initializes the Facebook SDK, the behavior of Facebook SDK functions are * undetermined if this function is not called. It should be called as early as possible. * @param applicationContext The application context * @param callback A callback called when initialize finishes. This will be called even if the * sdk is already initialized. */ public static synchronized void sdkInitialize( Context applicationContext, final InitializeCallback callback) { if (sdkInitialized) { if (callback != null) { callback.onInitialized(); } return; } Validate.notNull(applicationContext, "applicationContext"); // Don't throw for these validations here, just log an error. We'll throw when we actually // need them Validate.hasFacebookActivity(applicationContext, false); Validate.hasInternetPermissions(applicationContext, false); FacebookSdk.applicationContext = applicationContext.getApplicationContext(); // Make sure we've loaded default settings if we haven't already. FacebookSdk.loadDefaultsFromMetadata(FacebookSdk.applicationContext); // Load app settings from network so that dialog configs are available Utility.loadAppSettingsAsync(FacebookSdk.applicationContext, applicationId); // Fetch available protocol versions from the apps on the device NativeProtocol.updateAllAvailableProtocolVersionsAsync(); BoltsMeasurementEventListener.getInstance(FacebookSdk.applicationContext); cacheDir = new LockOnGetVariable<File>( new Callable<File>() { @Override public File call() throws Exception { return FacebookSdk.applicationContext.getCacheDir(); } }); FutureTask<Void> accessTokenLoadFutureTask = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws Exception { AccessTokenManager.getInstance().loadCurrentAccessToken(); ProfileManager.getInstance().loadCurrentProfile(); if (AccessToken.getCurrentAccessToken() != null && Profile.getCurrentProfile() == null) { // Access token and profile went out of sync due to a network or caching // issue, retry Profile.fetchProfileForCurrentAccessToken(); } if (callback != null) { callback.onInitialized(); } return null; } }); getExecutor().execute(accessTokenLoadFutureTask); sdkInitialized = true; }
/** * This function initializes the Facebook SDK, the behavior of Facebook SDK functions are * undetermined if this function is not called. It should be called as early as possible. * @param applicationContext The application context */ public static synchronized void sdkInitialize(Context applicationContext) { if (sdkInitialized == true) { return; } Validate.notNull(applicationContext, "applicationContext"); // Don't throw for these validations here, just log an error. We'll throw when we actually // need them Validate.hasFacebookActivity(applicationContext, false); Validate.hasInternetPermissions(applicationContext, false); FacebookSdk.applicationContext = applicationContext.getApplicationContext(); // Make sure we've loaded default settings if we haven't already. FacebookSdk.loadDefaultsFromMetadata(FacebookSdk.applicationContext); // Load app settings from network so that dialog configs are available Utility.loadAppSettingsAsync(FacebookSdk.applicationContext, applicationId); // Fetch available protocol versions from the apps on the device NativeProtocol.updateAllAvailableProtocolVersionsAsync(); BoltsMeasurementEventListener.getInstance(FacebookSdk.applicationContext); cacheDir = FacebookSdk.applicationContext.getCacheDir(); FutureTask<Void> accessTokenLoadFutureTask = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws Exception { AccessTokenManager.getInstance().loadCurrentAccessToken(); ProfileManager.getInstance().loadCurrentProfile(); if (AccessToken.getCurrentAccessToken() != null && Profile.getCurrentProfile() == null) { // Access token and profile went out of sync due to a network or caching // issue, retry Profile.fetchProfileForCurrentAccessToken(); } return null; } }); getExecutor().execute(accessTokenLoadFutureTask); sdkInitialized = true; }