LoginButton
A more recent version of this class is available. Check out the latest version.

A Log In/Log Out button that maintains session state and logs in/out for the app.

This control will create and use the active session upon construction if it has the available data (if the app ID is specified in the manifest). It will also open the active session if it does not require user interaction (i.e. if the session is in the SessionState.CREATED_TOKEN_LOADED state. Developers can override the use of the active session by calling the LoginButton.setSession(com.facebook.Session) method.

Extends:Button
Package:widget
Constructors
LoginButton(Context)

Create the LoginButton.

public LoginButton(Context context)
ParameterDescription
context
LoginButton(Context, AttributeSet)

Create the LoginButton by inflating from XML

public LoginButton(Context context, AttributeSet attrs)
ParameterDescription
context
attrs
LoginButton(Context, AttributeSet, int)

Create the LoginButton by inflating from XML and applying a style.

public LoginButton(Context context, AttributeSet attrs, int defStyle)
ParameterDescription
context
attrs
defStyle
Instance Methods
setOnErrorListener(OnErrorListener)

Sets an OnErrorListener for this instance of LoginButton to call into when certain exceptions occur.

public void setOnErrorListener(OnErrorListener onErrorListener)
ParameterDescription
onErrorListenerThe listener object to set
getOnErrorListener()

Returns the current OnErrorListener for this instance of LoginButton.

public OnErrorListener getOnErrorListener()
Returns
The OnErrorListener
setDefaultAudience(SessionDefaultAudience)

Sets the default audience to use when the session is opened. This value is only useful when specifying write permissions for the native login dialog.

public void setDefaultAudience(SessionDefaultAudience defaultAudience)
ParameterDescription
defaultAudienceThe default audience value to use
getDefaultAudience()

Gets the default audience to use when the session is opened. This value is only useful when specifying write permissions for the native login dialog.

public SessionDefaultAudience getDefaultAudience()
Returns
The default audience value to use
setReadPermissions(List)

Set the permissions to use when the session is opened. The permissions here can only be read permissions. If any publish permissions are included, the login attempt by the user will fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the LoginButton is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

public void setReadPermissions(List permissions)
ParameterDescription
permissionsThe read permissions to use
setReadPermissions(String)

Set the permissions to use when the session is opened. The permissions here can only be read permissions. If any publish permissions are included, the login attempt by the user will fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the LoginButton is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

public void setReadPermissions(String permissions)
ParameterDescription
permissionsThe read permissions to use
setPublishPermissions(List)

Set the permissions to use when the session is opened. The permissions here should only be publish permissions. If any read permissions are included, the login attempt by the user may fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the LoginButton is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

public void setPublishPermissions(List permissions)
ParameterDescription
permissionsThe read permissions to use
setPublishPermissions(String)

Set the permissions to use when the session is opened. The permissions here should only be publish permissions. If any read permissions are included, the login attempt by the user may fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the LoginButton is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

public void setPublishPermissions(String permissions)
ParameterDescription
permissionsThe read permissions to use
clearPermissions()

Clears the permissions currently associated with this LoginButton.

public void clearPermissions()
setLoginBehavior(SessionLoginBehavior)

Sets the login behavior for the session that will be opened. If null is specified, the default (SessionLoginBehavior.SSO_WITH_FALLBACK will be used.

public void setLoginBehavior(SessionLoginBehavior loginBehavior)
ParameterDescription
loginBehaviorThe SessionLoginBehavior that specifies what behaviors should be attempted during authorization.
getLoginBehavior()

Gets the login behavior for the session that will be opened. If null is returned, the default (SessionLoginBehavior.SSO_WITH_FALLBACK will be used.

public SessionLoginBehavior getLoginBehavior()
Returns
LoginBehavior The <a href='SessionLoginBehavior'>SessionLoginBehavior</a> that specifies what behaviors should be attempted during authorization.
setApplicationId(String)

Set the application ID to be used to open the session.

public void setApplicationId(String applicationId)
ParameterDescription
applicationIdThe application ID to use
getUserInfoChangedCallback()

Gets the callback interface that will be called when the current user changes.

public UserInfoChangedCallback getUserInfoChangedCallback()
Returns
The callback interface
setUserInfoChangedCallback(UserInfoChangedCallback)

Sets the callback interface that will be called when the current user changes.

public void setUserInfoChangedCallback(UserInfoChangedCallback userInfoChangedCallback)
ParameterDescription
userInfoChangedCallbackThe callback interface
setSessionStatusCallback(StatusCallback)

Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes. Note that updates will only be sent to the callback while the LoginButton is actually attached to a window.

public void setSessionStatusCallback(StatusCallback callback)
ParameterDescription
callbackThe callback interface
getSessionStatusCallback()

Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.

public StatusCallback getSessionStatusCallback()
Returns
The callback interface
setToolTipStyle(Style)

Sets the style (background) of the Tool Tip popup. Currently a blue style and a black style are supported. Blue is default

public void setToolTipStyle(Style nuxStyle)
ParameterDescription
nuxStyleThe style of the tool tip popup.
setToolTipMode(ToolTipMode)

Sets the mode of the Tool Tip popup. Currently supported modes are default (normal behavior), always_on (popup remains up until forcibly dismissed), and always_off (popup doesn't show)

public void setToolTipMode(ToolTipMode nuxMode)
ParameterDescription
nuxModeThe new mode for the tool tip
getToolTipMode()

Return the current LoginButton.ToolTipMode for this LoginButton

public ToolTipMode getToolTipMode()
Returns
The <a href='LoginButton.ToolTipMode'>LoginButton.ToolTipMode</a>
setToolTipDisplayTime(long)

Sets the amount of time (in milliseconds) that the tool tip will be shown to the user. The default is . Any value that is less than or equal to zero will cause the tool tip to be displayed indefinitely.

public void setToolTipDisplayTime(long displayTime)
ParameterDescription
displayTimeThe amount of time (in milliseconds) that the tool tip will be displayed to the user
getToolTipDisplayTime()

Gets the current amount of time (in ms) that the tool tip will be displayed to the user

public long getToolTipDisplayTime()
dismissToolTip()

Dismisses the Nux Tooltip if it is currently visible

public void dismissToolTip()
onActivityResult(int, int, Intent)

Provides an implementation for onActivityResult.onActivityResult that updates the Session based on information returned during the authorization flow. The Activity containing this view should forward the resulting onActivityResult call here to update the Session state based on the contents of the resultCode and data.

public boolean onActivityResult(int requestCode, int resultCode, Intent data)
ParameterDescription
requestCodeThe requestCode parameter from the forwarded call. When this onActivityResult occurs as part of Facebook authorization flow, this value is the activityCode passed to open or authorize.
resultCodeAn int containing the resultCode parameter from the forwarded call.
dataThe Intent passed as the data parameter from the forwarded call.
Returns
A boolean indicating whether the requestCode matched a pending authorization request for this Session.
setSession(Session)

Set the Session object to use instead of the active Session. Since a Session cannot be reused, if the user logs out from this Session, and tries to log in again, a new Active Session will be used instead.

If the passed in session is currently opened, this method will also attempt to load some user information for display (if needed).

public void setSession(Session newSession)
ParameterDescription
newSessionThe Session object to use
setFragment(Fragment)

Sets the fragment that contains this control. This allows the LoginButton to be embedded inside a Fragment, and will allow the fragment to receive the onActivityResult.onActivityResult(int, int, android.content.Intent) call rather than the Activity.

public void setFragment(Fragment fragment)
ParameterDescription
fragmentThe fragment that contains this control