Android SDK Version
  • java.lang.Object
    • com.facebook.FacebookSdk

public final class FacebookSdk
extends java.lang.Object
This class allows some customization of Facebook SDK behavior.
Nested Class Summary
Modifier and TypeClass and Description
static interface FacebookSdk.InitializeCallback
Callback passed to the sdkInitialize function.
Field Summary
Modifier and TypeField and Description
static java.lang.StringADVERTISER_ID_COLLECTION_ENABLED_PROPERTY
The key for the advertiserID collection in the Android manifest.
static java.lang.StringAPPLICATION_ID_PROPERTY
The key for the application ID in the Android manifest.
static java.lang.StringAPPLICATION_NAME_PROPERTY
The key for the application name in the Android manifest.
static java.lang.StringAUTO_INIT_ENABLED_PROPERTY
The key for the auto init SDK in the Android manifest.
static java.lang.StringAUTO_LOG_APP_EVENTS_ENABLED_PROPERTY
The key for the auto logging app events in the Android manifest.
static java.lang.StringCALLBACK_OFFSET_PROPERTY
The key for the callback off set in the Android manifest.
static java.lang.StringCLIENT_TOKEN_PROPERTY
The key for the client token in the Android manifest.
static java.lang.StringCODELESS_DEBUG_LOG_ENABLED_PROPERTY
The key for the auto log codeless in the Android manifest.
static java.lang.StringWEB_DIALOG_THEME
The key for the web dialog theme in the Android manifest.
Constructor Summary
Constructor and Description
FacebookSdk() 
Method Summary
Modifier and TypeMethod and Description
static voidaddLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production.
static voidclearLoggingBehaviors()
Certain logging behaviors are available for debugging beyond those that should be enabled in production.
static voidfullyInitialize()
Mark Facebook SDK fully intialized to make it works as expected.
static booleangetAdvertiserIDCollectionEnabled() 
static ContextgetApplicationContext()
The getter for the context of the current application.
static java.lang.StringgetApplicationId()
Gets the Facebook application ID for the current app.
static java.lang.StringgetApplicationName()
Gets the Facebook application name of the current app.
static java.lang.StringgetApplicationSignature(Context context)
Internal call please don't use directly.
static booleangetAutoInitEnabled() 
static booleangetAutoLogAppEventsEnabled()
Gets the flag used by AppEventsLogger
static java.io.FilegetCacheDir()
Gets the cache directory to use for caching responses, etc.
static intgetCallbackRequestCodeOffset()
Getter for the callback request code offset.
static java.lang.StringgetClientToken()
Gets the client token for the current app.
static booleangetCodelessDebugLogEnabled() 
static booleangetCodelessSetupEnabled() 
static java.util.concurrent.ExecutorgetExecutor()
Returns the Executor used by the SDK for non-AsyncTask background work.
static java.lang.StringgetFacebookDomain()
Gets the base Facebook domain to use when making Web requests; in production code this will always be "facebook.com".
static java.lang.StringgetGraphApiVersion()
Returns the Graph API version to use when making Graph requests.
static booleangetLimitEventAndDataUsage(Context 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.
static java.util.Set<LoggingBehavior>getLoggingBehaviors()
Certain logging behaviors are available for debugging beyond those that should be enabled in production.
static longgetOnProgressThreshold()
Gets the threshold used to report progress on requests.
static java.lang.StringgetSdkVersion()
Returns the current version of the Facebook SDK for Android as a string.
static booleanisDebugEnabled()
Indicates if we are in debug mode.
static booleanisFacebookRequestCode(int requestCode)
Returns true if the request code is within the range used by Facebook SDK requests.
static booleanisFullyInitialized()
Indicates whether the Facebook SDK has been fully initialized.
static booleanisInitialized()
Indicates whether the Facebook SDK has been initialized.
static booleanisLegacyTokenUpgradeSupported()
Indicates if the SDK should fallback and read the legacy token.
static booleanisLoggingBehaviorEnabled(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production.
static voidpublishInstallAsync(Context context, java.lang.String applicationId)
This method is public in order to be used by app events, please don't use directly.
static voidremoveLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production.
static voidsdkInitialize(Context applicationContext)
Deprecated. 
static voidsdkInitialize(Context applicationContext, FacebookSdk.InitializeCallback callback)
Deprecated. 
static voidsdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
Deprecated. 
static voidsdkInitialize(Context applicationContext, int callbackRequestCodeOffset, FacebookSdk.InitializeCallback callback)
Deprecated. 
static voidsetAdvertiserIDCollectionEnabled(boolean flag)
Sets the advertiserID collection flag for the application
static voidsetApplicationId(java.lang.String applicationId)
Sets the Facebook application ID for the current app.
static voidsetApplicationName(java.lang.String applicationName)
Sets the Facebook application name for the current app.
static voidsetAutoInitEnabled(boolean flag)
Sets the auto init SDK flag for the application
static voidsetAutoLogAppEventsEnabled(boolean flag)
Sets the auto logging events flag for the application AppEventsLogger
static voidsetCacheDir(java.io.File cacheDir)
Sets the cache directory to use for caching responses, etc.
static voidsetClientToken(java.lang.String clientToken)
Sets the Facebook client token for the current app.
static voidsetCodelessDebugLogEnabled(boolean flag)
Sets the codeless debug flag for the application
static voidsetExecutor(java.util.concurrent.Executor executor)
Sets the Executor used by the SDK for non-AsyncTask background work.
static voidsetFacebookDomain(java.lang.String facebookDomain)
Sets the base Facebook domain to use when making Web requests.
static voidsetGraphApiVersion(java.lang.String graphApiVersion)
Sets the Graph API version to use when making Graph requests.
static voidsetIsDebugEnabled(boolean enabled)
Used to enable or disable logging, and other debug features.
static voidsetLegacyTokenUpgradeSupported(boolean supported)
Setter for legacy token upgrade.
static voidsetLimitEventAndDataUsage(Context context, boolean limitEventUsage)
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.
static voidsetOnProgressThreshold(long threshold)
Sets the threshold used to report progress on requests.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail

APPLICATION_ID_PROPERTY

public static final java.lang.String APPLICATION_ID_PROPERTY
The key for the application ID in the Android manifest.

APPLICATION_NAME_PROPERTY

public static final java.lang.String APPLICATION_NAME_PROPERTY
The key for the application name in the Android manifest.

CLIENT_TOKEN_PROPERTY

public static final java.lang.String CLIENT_TOKEN_PROPERTY
The key for the client token in the Android manifest.

WEB_DIALOG_THEME

public static final java.lang.String WEB_DIALOG_THEME
The key for the web dialog theme in the Android manifest.

AUTO_INIT_ENABLED_PROPERTY

public static final java.lang.String AUTO_INIT_ENABLED_PROPERTY
The key for the auto init SDK in the Android manifest.

AUTO_LOG_APP_EVENTS_ENABLED_PROPERTY

public static final java.lang.String AUTO_LOG_APP_EVENTS_ENABLED_PROPERTY
The key for the auto logging app events in the Android manifest.

CODELESS_DEBUG_LOG_ENABLED_PROPERTY

public static final java.lang.String CODELESS_DEBUG_LOG_ENABLED_PROPERTY
The key for the auto log codeless in the Android manifest.

ADVERTISER_ID_COLLECTION_ENABLED_PROPERTY

public static final java.lang.String ADVERTISER_ID_COLLECTION_ENABLED_PROPERTY
The key for the advertiserID collection in the Android manifest.

CALLBACK_OFFSET_PROPERTY

public static final java.lang.String CALLBACK_OFFSET_PROPERTY
The key for the callback off set in the Android manifest.
Constructor Detail

FacebookSdk

public FacebookSdk()
Method Detail

sdkInitialize

@Deprecated
public static void sdkInitialize(Context applicationContext,
                                             int callbackRequestCodeOffset)
Deprecated. 
This function initializes the Facebook SDK. This function is called automatically on app start up if the proper entries are listed in the AndroidManifest, such as the facebook app id. This method can be called manually if needed. The behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible. As part of SDK initialization basic auto logging of app events will occur, this can be controlled via 'com.facebook.sdk.AutoLogAppEventsEnabled' manifest setting
Parameters:
applicationContext - The application context
callbackRequestCodeOffset - The 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

@Deprecated
public static void sdkInitialize(Context applicationContext,
                                             int callbackRequestCodeOffset,
                                             FacebookSdk.InitializeCallback callback)
Deprecated. 
This function initializes the Facebook SDK. This function is called automatically on app start up if the proper entries are listed in the AndroidManifest, such as the facebook app id. This method can be called manually if needed. The behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible. As part of SDK initialization basic auto logging of app events will occur, this can be controlled via 'com.facebook.sdk.AutoLogAppEventsEnabled' manifest setting
Parameters:
applicationContext - The application context
callbackRequestCodeOffset - The 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.
callback - A callback called when initialize finishes. This will be called even if the sdk is already initialized.

sdkInitialize

@Deprecated
public static void sdkInitialize(Context applicationContext)
Deprecated. 
This function initializes the Facebook SDK. This function is called automatically on app start up if the proper entries are listed in the AndroidManifest, such as the facebook app id. This method can bee called manually if needed. The behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible. As part of SDK initialization basic auto logging of app events will occur, this can be controlled via 'com.facebook.sdk.AutoLogAppEventsEnabled' manifest setting
Parameters:
applicationContext - The application context

sdkInitialize

@Deprecated
public static void sdkInitialize(Context applicationContext,
                                             FacebookSdk.InitializeCallback callback)
Deprecated. 
This function initializes the Facebook SDK. This function is called automatically on app start up if the proper entries are listed in the AndroidManifest, such as the facebook app id. This method can bee called manually if needed. The behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible. As part of SDK initialization basic auto logging of app events will occur, this can be controlled via 'com.facebook.sdk.AutoLogAppEventsEnabled' manifest setting
Parameters:
applicationContext - The application context
callback - A callback called when initialize finishes. This will be called even if the sdk is already initialized.

isInitialized

public static boolean isInitialized()
Indicates whether the Facebook SDK has been initialized.
Returns:
true if initialized, false if not

isFullyInitialized

public static boolean isFullyInitialized()
Indicates whether the Facebook SDK has been fully initialized. Facebook SDK won't work before fully initialized.
Returns:
true if fully initialized, false if not

fullyInitialize

public static void fullyInitialize()
Mark Facebook SDK fully intialized to make it works as expected.

getLoggingBehaviors

public static java.util.Set<LoggingBehavior> 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.
Returns:
a set containing enabled logging behaviors

addLoggingBehavior

public static void addLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production. Enables a particular extended logging in the SDK.
Parameters:
behavior - The LoggingBehavior to enable

removeLoggingBehavior

public static void removeLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production. Disables a particular extended logging behavior in the SDK.
Parameters:
behavior - The LoggingBehavior to disable

clearLoggingBehaviors

public static void clearLoggingBehaviors()
Certain logging behaviors are available for debugging beyond those that should be enabled in production. Disables all extended logging behaviors.

isLoggingBehaviorEnabled

public static boolean isLoggingBehaviorEnabled(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled in production. Checks if a particular extended logging behavior is enabled.
Parameters:
behavior - The LoggingBehavior to check
Returns:
whether behavior is enabled

isDebugEnabled

public static boolean isDebugEnabled()
Indicates if we are in debug mode.

setIsDebugEnabled

public static void setIsDebugEnabled(boolean enabled)
Used to enable or disable logging, and other debug features. Defaults to BuildConfig.DEBUG.
Parameters:
enabled - Debug features (like logging) are enabled if true, disabled if false.

isLegacyTokenUpgradeSupported

public static boolean isLegacyTokenUpgradeSupported()
Indicates if the SDK should fallback and read the legacy token. This is turned off by default for performance.
Returns:
if the legacy token upgrade is supported.

setLegacyTokenUpgradeSupported

public static void setLegacyTokenUpgradeSupported(boolean supported)
Setter for legacy token upgrade.
Parameters:
supported - True if upgrade should be supported.

getExecutor

public static java.util.concurrent.Executor 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.
Returns:
an Executor used by the SDK. This will never be null.

setExecutor

public static void setExecutor(java.util.concurrent.Executor executor)
Sets the Executor used by the SDK for non-AsyncTask background work.
Parameters:
executor - the Executor to use; must not be null.

getFacebookDomain

public static java.lang.String getFacebookDomain()
Gets the base Facebook domain to use when making Web requests; in production code this will always be "facebook.com".
Returns:
the Facebook domain

setFacebookDomain

public static void setFacebookDomain(java.lang.String facebookDomain)
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.
Parameters:
facebookDomain - the base domain to use instead of "facebook.com"

getApplicationContext

public static Context getApplicationContext()
The getter for the context of the current application.
Returns:
The context of the current application.

setGraphApiVersion

public static void setGraphApiVersion(java.lang.String graphApiVersion)
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.
Parameters:
graphApiVersion - the Graph API version, it should be of the form ServerProtocol.getDefaultAPIVersion()

getGraphApiVersion

public static java.lang.String 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.
Returns:
the Graph API version to use.

publishInstallAsync

public static void publishInstallAsync(Context context,
                                       java.lang.String applicationId)
This method is public in order to be used by app events, please don't use directly.
Parameters:
context - The application context.
applicationId - The application id.

getSdkVersion

public static java.lang.String getSdkVersion()
Returns the current version of the Facebook SDK for Android as a string.
Returns:
the current version of the SDK

getLimitEventAndDataUsage

public static boolean getLimitEventAndDataUsage(Context 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.
Parameters:
context - Used to read the value.

setLimitEventAndDataUsage

public static void setLimitEventAndDataUsage(Context context,
                                             boolean limitEventUsage)
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.
Parameters:
context - Used to persist this value across app runs.

getOnProgressThreshold

public static long getOnProgressThreshold()
Gets the threshold used to report progress on requests.

setOnProgressThreshold

public static void setOnProgressThreshold(long threshold)
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.
Parameters:
threshold - The number of bytes progressed to force a callback.

getApplicationSignature

public static java.lang.String getApplicationSignature(Context context)
Internal call please don't use directly.
Parameters:
context - The application context.
Returns:
The application signature.

getApplicationId

public static java.lang.String 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().
Returns:
the application ID

setApplicationId

public static void setApplicationId(java.lang.String applicationId)
Sets the Facebook application ID for the current app.
Parameters:
applicationId - the application ID

getApplicationName

public static java.lang.String 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().
Returns:
the application name

setApplicationName

public static void setApplicationName(java.lang.String applicationName)
Sets the Facebook application name for the current app.
Parameters:
applicationName - the application name

getClientToken

public static java.lang.String getClientToken()
Gets the client token for the current app. This will be null unless explicitly set or unless loadDefaultsFromMetadata has been called.
Returns:
the client token

setClientToken

public static void setClientToken(java.lang.String clientToken)
Sets the Facebook client token for the current app.
Parameters:
clientToken - the client token

getAutoInitEnabled

public static boolean getAutoInitEnabled()
Returns:
the auto init SDK flag for the application

setAutoInitEnabled

public static void setAutoInitEnabled(boolean flag)
Sets the auto init SDK flag for the application
Parameters:
flag - true or false When flag is false, SDK is not fully initialized.

getAutoLogAppEventsEnabled

public static boolean getAutoLogAppEventsEnabled()
Gets the flag used by AppEventsLogger
Returns:
the auto logging events flag for the application

setAutoLogAppEventsEnabled

public static void setAutoLogAppEventsEnabled(boolean flag)
Sets the auto logging events flag for the application AppEventsLogger
Parameters:
flag - true or false When flag is false, events will not be logged, see AutomaticAnalyticsLogger

getCodelessDebugLogEnabled

public static boolean getCodelessDebugLogEnabled()
Returns:
the codeless debug flag for the application

getCodelessSetupEnabled

public static boolean getCodelessSetupEnabled()
Returns:
the codeless enabled flag for the application

setAdvertiserIDCollectionEnabled

public static void setAdvertiserIDCollectionEnabled(boolean flag)
Sets the advertiserID collection flag for the application
Parameters:
flag - true or false

getAdvertiserIDCollectionEnabled

public static boolean getAdvertiserIDCollectionEnabled()
Returns:
the advertiserID collection flag for the application

setCodelessDebugLogEnabled

public static void setCodelessDebugLogEnabled(boolean flag)
Sets the codeless debug flag for the application
Parameters:
flag - true or false

getCacheDir

public static java.io.File 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.
Returns:
the cache directory

setCacheDir

public static void setCacheDir(java.io.File cacheDir)
Sets the cache directory to use for caching responses, etc.
Parameters:
cacheDir - the cache directory

getCallbackRequestCodeOffset

public static int 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.
Returns:
The callback request code offset.

isFacebookRequestCode

public static boolean isFacebookRequestCode(int requestCode)
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.
Parameters:
requestCode - the request code to check.
Returns:
true if the request code is within the range used by the Facebook SDK.