-
public final class FacebookSdkThis class allows some customization of Facebook SDK behavior.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceFacebookSdk.InitializeCallbackCallback passed to the sdkInitialize function.
public interfaceFacebookSdk.GraphRequestCreatorAbstraction for better testability.
-
Field Summary
-
Method Summary
Modifier and Type Method Description static ExecutorgetExecutor()Returns the Executor used by the SDK for non-AsyncTask background work. static voidsetExecutor(Executor executor)Sets the Executor used by the SDK for non-AsyncTask background work. static StringgetApplicationId()Gets the Facebook application ID for the current app. static voidsetApplicationId(String applicationId)Sets the Facebook application ID for the current app. static StringgetApplicationName()Gets the Facebook application name of the current app. static voidsetApplicationName(String applicationName)Sets the Facebook application name for the current app. static voidsetCodelessDebugLogEnabled(boolean flag)Sets the codeless debug flag for the application static StringgetFacebookDomain()Gets the base Facebook domain to use when making Web Requests; in production code this willalways be "facebook.com". static voidsetFacebookDomain(String facebookDomain)Sets the base Facebook domain to use when making Web requests. static voidsetOnProgressThreshold(long threshold)Sets the threshold used to report progress on requests. static booleanisDebugEnabled()Indicates if we are in debug mode. static voidsetIsDebugEnabled(boolean enabled)Used to enable or disable logging, and other debug features. static booleanisLegacyTokenUpgradeSupported()Indicates if the SDK should fallback and read the legacy token. static voidsetCacheDir(File cacheDir)Sets the cache directory to use for caching responses, etc. static ContextgetApplicationContext()The getter for the context of the current application. static intgetCallbackRequestCodeOffset()Getter for the callback request code offset. static StringgetGraphApiVersion()Returns the Graph API version to use when making Graph requests. static voidsetGraphApiVersion(String graphApiVersion)Sets the Graph API version to use when making Graph requests. static voidsetGraphRequestCreator(FacebookSdk.GraphRequestCreator graphRequestCreator)static synchronized voidsdkInitialize(Context applicationContext, int callbackRequestCodeOffset)This function initializes the Facebook SDK. static synchronized voidsdkInitialize(Context applicationContext, int callbackRequestCodeOffset, FacebookSdk.InitializeCallback callback)This function initializes the Facebook SDK. static synchronized voidsdkInitialize(Context applicationContext)This function initializes the Facebook SDK. static synchronized voidsdkInitialize(Context applicationContext, FacebookSdk.InitializeCallback callback)This function initializes the Facebook SDK. static booleanisInitialized()Indicates whether the Facebook SDK has been initialized. static synchronized booleanisFullyInitialized()Indicates whether the Facebook SDK has been fully initialized. static voidfullyInitialize()Mark Facebook SDK fully intialized to make it works as expected. static voidaddLoggingBehavior(LoggingBehavior behavior)Certain logging behaviors are available for debugging beyond those that should be enabled inproduction. static voidremoveLoggingBehavior(LoggingBehavior behavior)Certain logging behaviors are available for debugging beyond those that should be enabled inproduction. static voidclearLoggingBehaviors()Certain logging behaviors are available for debugging beyond those that should be enabled inproduction. static booleanisLoggingBehaviorEnabled(LoggingBehavior behavior)Certain logging behaviors are available for debugging beyond those that should be enabled inproduction. static voidsetLegacyTokenUpgradeSupported(boolean supported)Setter for legacy token upgrade. static StringgetGraphDomain()Gets the base Facebook domain to use when making Graph API requests; in production code thiswill normally be "facebook.com". static voidpublishInstallAsync(Context context, String applicationId)This method is public in order to be used by app events, please don't use directly. static StringgetSdkVersion()Returns the current version of the Facebook SDK for Android as a string. static booleangetLimitEventAndDataUsage(Context context)Returns whether data such as those generated through AppEventsLogger and sent to Facebookshould be restricted from being used for purposes other than analytics and conversions, such astargeting ads to this user. static voidsetLimitEventAndDataUsage(Context context, boolean limitEventUsage)Sets whether data such as those generated through AppEventsLogger and sent to Facebook shouldbe restricted from being used for purposes other than analytics and conversions, such astargeting ads to this user. static StringgetApplicationSignature(Context context)Internal call please don't use directly. static StringgetClientToken()Gets the client token for the current app. static voidsetClientToken(String clientToken)Sets the Facebook client token for the current app. static booleangetAutoInitEnabled()static voidsetAutoInitEnabled(boolean flag)Sets the auto init SDK flag for the application static booleangetAutoLogAppEventsEnabled()Gets the flag used by com.facebook.appevents.AppEventsLogger static voidsetAutoLogAppEventsEnabled(boolean flag)Sets the auto logging events flag for the application static booleangetCodelessSetupEnabled()static voidsetAdvertiserIDCollectionEnabled(boolean flag)Sets the advertiserID collection flag for the application static booleangetAdvertiserIDCollectionEnabled()static booleangetMonitorEnabled()Gets the flag of Monitor Feature static voidsetMonitorEnabled(boolean flag)Sets the monitor flag for the application static voidsetDataProcessingOptions(Array<String> options)Sets data processing options static voidsetDataProcessingOptions(Array<String> options, int country, int state)Sets data processing options static booleanisFacebookRequestCode(int requestCode)Returns true if the request code is within the range used by Facebook SDK requests. -
-
Method Detail
-
getExecutor
static 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.
-
setExecutor
static void setExecutor(Executor executor)
Sets the Executor used by the SDK for non-AsyncTask background work.
- Parameters:
executor- the Executor to use; must not be null.
-
getApplicationId
static String getApplicationId()
Gets the Facebook application ID for the current app. This should only be called after the SDKhas been initialized by calling FacebookSdk.sdkInitialize().
-
setApplicationId
static void setApplicationId(String applicationId)
Sets the Facebook application ID for the current app.
- Parameters:
applicationId- the application ID
-
getApplicationName
@Nullable() static String getApplicationName()
Gets the Facebook application name of the current app. This should only be called after the SDKhas been initialized by calling FacebookSdk.sdkInitialize().
-
setApplicationName
static void setApplicationName(String applicationName)
Sets the Facebook application name for the current app.
- Parameters:
applicationName- the application name
-
setCodelessDebugLogEnabled
static void setCodelessDebugLogEnabled(boolean flag)
Sets the codeless debug flag for the application
- Parameters:
flag- true or false
-
getFacebookDomain
static String getFacebookDomain()
Gets the base Facebook domain to use when making Web Requests; in production code this willalways be "facebook.com".
This is required for PlatformDialogs which always need to use facebook.com
-
setFacebookDomain
static void setFacebookDomain(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.
Updating this will also affect getGraphDomain calls. Setting "beta.facebook.com" will returnbeta.fb.gg if using the gaming domain for example.
- Parameters:
facebookDomain- the base domain to use instead of "facebook.
-
setOnProgressThreshold
static void setOnProgressThreshold(long threshold)
Sets the threshold used to report progress on requests. Note that the value will be read whenthe request is started and cannot be changed during a request (or batch) execution.
- Parameters:
threshold- The number of bytes progressed to force a callback.
-
isDebugEnabled
static boolean isDebugEnabled()
Indicates if we are in debug mode.
-
setIsDebugEnabled
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
static boolean isLegacyTokenUpgradeSupported()
Indicates if the SDK should fallback and read the legacy token. This is turned off by defaultfor performance.
-
setCacheDir
static void setCacheDir(File cacheDir)
Sets the cache directory to use for caching responses, etc.
- Parameters:
cacheDir- the cache directory
-
getApplicationContext
static Context getApplicationContext()
The getter for the context of the current application.
-
getCallbackRequestCodeOffset
static int getCallbackRequestCodeOffset()
Getter for the callback request code offset. The request codes starting at this offset and thenext 100 values are used by the Facebook SDK.
-
getGraphApiVersion
static String getGraphApiVersion()
Returns the Graph API version to use when making Graph requests. This defaults to the latestGraph API version at the time when the Facebook SDK is shipped.
-
setGraphApiVersion
static void setGraphApiVersion(String graphApiVersion)
Sets the Graph API version to use when making Graph requests. This defaults to the latest GraphAPI version at the time when the Facebook SDK is shipped.
- Parameters:
graphApiVersion- the Graph API version, it should be of the formServerProtocol.
-
setGraphRequestCreator
static void setGraphRequestCreator(FacebookSdk.GraphRequestCreator graphRequestCreator)
-
sdkInitialize
@Deprecated() static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
This function initializes the Facebook SDK. This function is called automatically on app startup if the proper entries are listed in the AndroidManifest, such as the facebook app id. Thismethod can be called manually if needed. The behavior of Facebook SDK functions areundetermined if this function is not called. It should be called as early as possible. As partof 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 contextcallbackRequestCodeOffset- The request code offset that Facebook activities will becalled with.
-
sdkInitialize
@Deprecated() static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset, FacebookSdk.InitializeCallback callback)
This function initializes the Facebook SDK. This function is called automatically on app startup if the proper entries are listed in the AndroidManifest, such as the facebook app id. Thismethod can be called manually if needed. The behavior of Facebook SDK functions areundetermined if this function is not called. It should be called as early as possible. As partof 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 contextcallbackRequestCodeOffset- The request code offset that Facebook activities will becalled with.callback- A callback called when initialize finishes.
-
sdkInitialize
@Deprecated() static synchronized void sdkInitialize(Context applicationContext)
This function initializes the Facebook SDK. This function is called automatically on app startup if the proper entries are listed in the AndroidManifest, such as the facebook app id. Thismethod can be called manually if needed. The behavior of Facebook SDK functions areundetermined if this function is not called. It should be called as early as possible. As partof 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 @Deprecated sdkInitialize and activateApp are called automatically onapplication start.
-
sdkInitialize
@Deprecated() static synchronized void sdkInitialize(Context applicationContext, FacebookSdk.InitializeCallback callback)
This function initializes the Facebook SDK. This function is called automatically on app startup if the proper entries are listed in the AndroidManifest, such as the facebook app id. Thismethod can bee called manually if needed. The behavior of Facebook SDK functions areundetermined if this function is not called. It should be called as early as possible. As partof 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 contextcallback- A callback called when initialize finishes.
-
isInitialized
static boolean isInitialized()
Indicates whether the Facebook SDK has been initialized.
-
isFullyInitialized
static synchronized boolean isFullyInitialized()
Indicates whether the Facebook SDK has been fully initialized.
Facebook SDK won't work before fully initialized.
-
fullyInitialize
static void fullyInitialize()
Mark Facebook SDK fully intialized to make it works as expected.
-
addLoggingBehavior
static void addLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled inproduction.
Enables a particular extended logging in the SDK.
- Parameters:
behavior- The LoggingBehavior to enable
-
removeLoggingBehavior
static void removeLoggingBehavior(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled inproduction.
Disables a particular extended logging behavior in the SDK.
- Parameters:
behavior- The LoggingBehavior to disable
-
clearLoggingBehaviors
static void clearLoggingBehaviors()
Certain logging behaviors are available for debugging beyond those that should be enabled inproduction.
Disables all extended logging behaviors.
-
isLoggingBehaviorEnabled
static boolean isLoggingBehaviorEnabled(LoggingBehavior behavior)
Certain logging behaviors are available for debugging beyond those that should be enabled inproduction.
Checks if a particular extended logging behavior is enabled.
- Parameters:
behavior- The LoggingBehavior to check
-
setLegacyTokenUpgradeSupported
static void setLegacyTokenUpgradeSupported(boolean supported)
Setter for legacy token upgrade.
- Parameters:
supported- True if upgrade should be supported.
-
getGraphDomain
static String getGraphDomain()
Gets the base Facebook domain to use when making Graph API requests; in production code thiswill normally be "facebook.com". However certain Access Tokens are meant to be used with otherdomains. Currently gaming -> fb.gg
This checks the current Access Token (if any) and returns the correct domain to use.
-
publishInstallAsync
static void publishInstallAsync(Context context, 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
static String getSdkVersion()
Returns the current version of the Facebook SDK for Android as a string.
-
getLimitEventAndDataUsage
static boolean getLimitEventAndDataUsage(Context context)
Returns whether data such as those generated through AppEventsLogger and sent to Facebookshould be restricted from being used for purposes other than analytics and conversions, such astargeting ads to this user. Defaults to false. This value is stored on the device and persistsacross app launches.
- Parameters:
context- Used to read the value.
-
setLimitEventAndDataUsage
static void setLimitEventAndDataUsage(Context context, boolean limitEventUsage)
Sets whether data such as those generated through AppEventsLogger and sent to Facebook shouldbe restricted from being used for purposes other than analytics and conversions, such astargeting ads to this user. Defaults to false. This value is stored on the device and persistsacross app launches. Changes to this setting will apply to app events currently queued to beflushed.
- Parameters:
context- Used to persist this value across app runs.
-
getApplicationSignature
static String getApplicationSignature(Context context)
Internal call please don't use directly.
- Parameters:
context- The application context.
-
getClientToken
static String getClientToken()
Gets the client token for the current app. This will be null unless explicitly set or unlessloadDefaultsFromMetadata has been called.
-
setClientToken
static void setClientToken(String clientToken)
Sets the Facebook client token for the current app.
- Parameters:
clientToken- the client token
-
getAutoInitEnabled
static boolean getAutoInitEnabled()
-
setAutoInitEnabled
static void setAutoInitEnabled(boolean flag)
Sets the auto init SDK flag for the application
- Parameters:
flag- true or falseWhen flag is false, SDK is not fully initialized.
-
getAutoLogAppEventsEnabled
static boolean getAutoLogAppEventsEnabled()
Gets the flag used by com.facebook.appevents.AppEventsLogger
-
setAutoLogAppEventsEnabled
static void setAutoLogAppEventsEnabled(boolean flag)
Sets the auto logging events flag for the application
- Parameters:
flag- true or falseWhen flag is false, events will not be logged, see
-
getCodelessSetupEnabled
static boolean getCodelessSetupEnabled()
-
setAdvertiserIDCollectionEnabled
static void setAdvertiserIDCollectionEnabled(boolean flag)
Sets the advertiserID collection flag for the application
- Parameters:
flag- true or false
-
getAdvertiserIDCollectionEnabled
static boolean getAdvertiserIDCollectionEnabled()
-
getMonitorEnabled
static boolean getMonitorEnabled()
Gets the flag of Monitor Feature
-
setMonitorEnabled
static void setMonitorEnabled(boolean flag)
Sets the monitor flag for the application
- Parameters:
flag- true or false
-
setDataProcessingOptions
static void setDataProcessingOptions(Array<String> options)
Sets data processing options
-
setDataProcessingOptions
static void setDataProcessingOptions(Array<String> options, int country, int state)
Sets data processing options
-
isFacebookRequestCode
static boolean isFacebookRequestCode(int requestCode)
Returns true if the request code is within the range used by Facebook SDK requests. This doesnot include request codes that you explicitly set on the dialogs, buttons or LoginManager. Therange of request codes that the SDK uses starts at the callbackRequestCodeOffset and continuesfor the next 100 values.
- Parameters:
requestCode- the request code to check.
-
-
-
-