FacebookSdk

This class allows some customization of Facebook SDK behavior.

Extends:Object
Package:facebook
Constructors
FacebookSdk()
public FacebookSdk()
Class Methods
sdkInitialize(Context, int)

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.

public static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
ParameterDescription
applicationContextThe application context
callbackRequestCodeOffsetThe request code offset that Facebook activities will be called with. Please do not use the range between the value you set and another 100 entries after it in your other requests.
sdkInitialize(Context, int, InitializeCallback)

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.

public static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset, InitializeCallback callback)
ParameterDescription
applicationContextThe application context
callbackRequestCodeOffsetThe request code offset that Facebook activities will be called with. Please do not use the range between the value you set and another 100 entries after it in your other requests.
callbackA callback called when initialize finishes. This will be called even if the sdk is already initialized.
sdkInitialize(Context)

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.

public static synchronized void sdkInitialize(Context applicationContext)
ParameterDescription
applicationContextThe application context
sdkInitialize(Context, InitializeCallback)

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.

public static synchronized void sdkInitialize(Context applicationContext, InitializeCallback callback)
ParameterDescription
applicationContextThe application context
callbackA callback called when initialize finishes. This will be called even if the sdk is already initialized.
isInitialized()

Indicates whether the Facebook SDK has been initialized.

public static synchronized boolean isInitialized()
Returns
True if initialized, false if not
getLoggingBehaviors()

Certain logging behaviors are available for debugging beyond those that should be enabled in production.

Returns the types of extended logging that are currently enabled.

public static Set getLoggingBehaviors()
Returns
A set containing enabled logging behaviors
addLoggingBehavior(LoggingBehavior)

Certain logging behaviors are available for debugging beyond those that should be enabled in production.

Enables a particular extended logging in the SDK.

public static void addLoggingBehavior(LoggingBehavior behavior)
ParameterDescription
behaviorThe LoggingBehavior to enable
removeLoggingBehavior(LoggingBehavior)

Certain logging behaviors are available for debugging beyond those that should be enabled in production.

Disables a particular extended logging behavior in the SDK.

public static void removeLoggingBehavior(LoggingBehavior behavior)
ParameterDescription
behaviorThe LoggingBehavior to disable
clearLoggingBehaviors()

Certain logging behaviors are available for debugging beyond those that should be enabled in production.

Disables all extended logging behaviors.

public static void clearLoggingBehaviors()
isLoggingBehaviorEnabled(LoggingBehavior)

Certain logging behaviors are available for debugging beyond those that should be enabled in production.

Checks if a particular extended logging behavior is enabled.

public static boolean isLoggingBehaviorEnabled(LoggingBehavior behavior)
ParameterDescription
behaviorThe LoggingBehavior to check
Returns
Whether behavior is enabled
isDebugEnabled()

Indicates if we are in debug mode.

public static boolean isDebugEnabled()
setIsDebugEnabled(boolean)

Used to enable or disable logging, and other debug features. Defaults to BuildConfig.DEBUG.

public static void setIsDebugEnabled(boolean enabled)
ParameterDescription
enabledDebug features (like logging) are enabled if true, disabled if false.
isLegacyTokenUpgradeSupported()

Indicates if the SDK should fallback and read the legacy token. This is turned off by default for performance.

public static boolean isLegacyTokenUpgradeSupported()
Returns
If the legacy token upgrade is supported.
setLegacyTokenUpgradeSupported(boolean)

Setter for legacy token upgrade.

public static void setLegacyTokenUpgradeSupported(boolean supported)
ParameterDescription
supportedTrue if upgrade should be supported.
getExecutor()

Returns the Executor used by the SDK for non-AsyncTask background work.

By default this uses AsyncTask Executor via reflection if the API level is high enough. Otherwise this creates a new Executor with defaults similar to those used in AsyncTask.

public static Executor getExecutor()
Returns
An Executor used by the SDK. This will never be null.
setExecutor(Executor)

Sets the Executor used by the SDK for non-AsyncTask background work.

public static void setExecutor(Executor executor)
ParameterDescription
executorThe Executor to use; must not be null.
getFacebookDomain()

Gets the base Facebook domain to use when making Web requests; in production code this will always be "facebook.com".

public static String getFacebookDomain()
Returns
The Facebook domain
setFacebookDomain(String)

Sets the base Facebook domain to use when making Web requests. This defaults to "facebook.com", but may be overridden to, e.g., "beta.facebook.com" to direct requests at a different domain. This method should never be called from production code.

public static void setFacebookDomain(String facebookDomain)
ParameterDescription
facebookDomainThe base domain to use instead of "facebook.com"
getApplicationContext()

The getter for the context of the current application.

public static Context getApplicationContext()
Returns
The context of the current application.
setGraphApiVersion(String)

Sets the Graph API version to use when making Graph requests. This defaults to the latest Graph API version at the time when the Facebook SDK is shipped.

public static void setGraphApiVersion(String graphApiVersion)
ParameterDescription
graphApiVersionThe Graph API version, it should be of the form "v2.7"
getGraphApiVersion()

Returns the Graph API version to use when making Graph requests. This defaults to the latest Graph API version at the time when the Facebook SDK is shipped.

public static String getGraphApiVersion()
Returns
The Graph API version to use.
publishInstallAsync(Context, String)

This method is public in order to be used by app events, please don't use directly.

public static void publishInstallAsync(Context context, String applicationId)
ParameterDescription
contextThe application context.
applicationIdThe application id.
getSdkVersion()

Returns the current version of the Facebook SDK for Android as a string.

public static String getSdkVersion()
Returns
The current version of the SDK
getLimitEventAndDataUsage(Context)

Returns whether data such as those generated through AppEventsLogger and sent to Facebook should be restricted from being used for purposes other than analytics and conversions, such as targeting ads to this user. Defaults to false. This value is stored on the device and persists across app launches.

public static boolean getLimitEventAndDataUsage(Context context)
ParameterDescription
contextUsed to read the value.
setLimitEventAndDataUsage(Context, boolean)

Sets whether data such as those generated through AppEventsLogger and sent to Facebook should be restricted from being used for purposes other than analytics and conversions, such as targeting ads to this user. Defaults to false. This value is stored on the device and persists across app launches. Changes to this setting will apply to app events currently queued to be flushed.

public static void setLimitEventAndDataUsage(Context context, boolean limitEventUsage)
ParameterDescription
contextUsed to persist this value across app runs.
limitEventUsage
getOnProgressThreshold()

Gets the threshold used to report progress on requests.

public static long getOnProgressThreshold()
setOnProgressThreshold(long)

Sets the threshold used to report progress on requests. Note that the value will be read when the request is started and cannot be changed during a request (or batch) execution.

public static void setOnProgressThreshold(long threshold)
ParameterDescription
thresholdThe number of bytes progressed to force a callback.
getApplicationSignature(Context)

Internal call please don't use directly.

public static String getApplicationSignature(Context context)
ParameterDescription
contextThe application context.
Returns
The application signature.
getApplicationId()

Gets the Facebook application ID for the current app. This should only be called after the SDK has been initialized by calling FacebookSdk.sdkInitialize().

public static String getApplicationId()
Returns
The application ID
setApplicationId(String)

Sets the Facebook application ID for the current app.

public static void setApplicationId(String applicationId)
ParameterDescription
applicationIdThe application ID
getApplicationName()

Gets the Facebook application name of the current app. This should only be called after the SDK has been initialized by calling FacebookSdk.sdkInitialize().

public static String getApplicationName()
Returns
The application name
setApplicationName(String)

Sets the Facebook application name for the current app.

public static void setApplicationName(String applicationName)
ParameterDescription
applicationNameThe application name
getClientToken()

Gets the client token for the current app. This will be null unless explicitly set or unless loadDefaultsFromMetadata has been called.

public static String getClientToken()
Returns
The client token
setClientToken(String)

Sets the Facebook client token for the current app.

public static void setClientToken(String clientToken)
ParameterDescription
clientTokenThe client token
getWebDialogTheme()

Gets the theme used by WebDialog

public static int getWebDialogTheme()
Returns
The theme
setWebDialogTheme(int)

Sets the theme used by WebDialog

public static void setWebDialogTheme(int theme)
ParameterDescription
themeA theme to use
getCacheDir()

Gets the cache directory to use for caching responses, etc. The default will be the value returned by Context.getCacheDir() when the SDK was initialized, but it can be overridden.

public static File getCacheDir()
Returns
The cache directory
setCacheDir(File)

Sets the cache directory to use for caching responses, etc.

public static void setCacheDir(File cacheDir)
ParameterDescription
cacheDirThe cache directory
getCallbackRequestCodeOffset()

Getter for the callback request code offset. The request codes starting at this offset and the next 100 values are used by the Facebook SDK.

public static int getCallbackRequestCodeOffset()
Returns
The callback request code offset.
isFacebookRequestCode(int)

Returns true if the request code is within the range used by Facebook SDK requests. This does not include request codes that you explicitly set on the dialogs, buttons or LoginManager. The range of request codes that the SDK uses starts at the callbackRequestCodeOffset and continues for the next 100 values.

public static boolean isFacebookRequestCode(int requestCode)
ParameterDescription
requestCodeThe request code to check.
Returns
True if the request code is within the range used by the Facebook SDK.
Constants
APPLICATION_ID_PROPERTY
The key for the application ID in the Android manifest.
public static final String APPLICATION_ID_PROPERTY
APPLICATION_NAME_PROPERTY
The key for the application name in the Android manifest.
public static final String APPLICATION_NAME_PROPERTY
CLIENT_TOKEN_PROPERTY
The key for the client token in the Android manifest.
public static final String CLIENT_TOKEN_PROPERTY
WEB_DIALOG_THEME
The key for the web dialog theme in the Android manifest.
public static final String WEB_DIALOG_THEME