A Fragment that displays a Login/Logout button as well as the user's profile picture and name when logged in.
This Fragment 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 UserSettingsFragment.setSession(com.facebook.Session) method.
Estende: | Fragment |
Pacote: | widget |
UserSettingsFragment()
public UserSettingsFragment()
setSession(Session)
Use the supplied Session object instead of the active Session.
public void setSession(Session newSession)
Parâmetro | Descrição |
---|---|
newSession | The Session object to use |
onSessionStateChange(SessionState, Exception)
Called when the session state changes. Override this method to take action on session state changes.
protected void onSessionStateChange(SessionState state, Exception exception)
Parâmetro | Descrição |
---|---|
state | The new state |
exception | Any exceptions that occurred during the state change |
getSession()
Gets the current Session.
protected final Session getSession()
isSessionOpen()
Determines whether the current session is open.
protected final boolean isSessionOpen()
getSessionState()
Gets the current state of the session or null if no session has been created.
protected final SessionState getSessionState()
getAccessToken()
Gets the access token associated with the current session or null if no session has been created.
protected final String getAccessToken()
getExpirationDate()
Gets the date at which the current session will expire or null if no session has been created.
protected final Date getExpirationDate()
closeSession()
Closes the current session.
protected final void closeSession()
closeSessionAndClearTokenInformation()
Closes the current session as well as clearing the token cache.
protected final void closeSessionAndClearTokenInformation()
getSessionPermissions()
Gets the permissions associated with the current session or null if no session has been created.
protected final List getSessionPermissions()
openSession()
Opens a new session. This method will use the application id from the associated meta-data value and an empty list of permissions.
protected final void openSession()
openSessionForRead(String, List)
Opens a new session with read permissions. If either applicationID or permissions is null, this method will default to using the values from the associated meta-data value and an empty list respectively.
protected final void openSessionForRead(String applicationId, List permissions)
Parâmetro | Descrição |
---|---|
applicationId | The applicationID, can be null |
permissions | The permissions list, can be null |
openSessionForRead(String, List, SessionLoginBehavior, int)
Opens a new session with read permissions. If either applicationID or permissions is null, this method will default to using the values from the associated meta-data value and an empty list respectively.
protected final void openSessionForRead(String applicationId, List permissions, SessionLoginBehavior behavior, int activityCode)
Parâmetro | Descrição |
---|---|
applicationId | The applicationID, can be null |
permissions | The permissions list, can be null |
behavior | The login behavior to use with the session |
activityCode | The activity code to use for the SSO activity |
openSessionForPublish(String, List)
Opens a new session with publish permissions. If either applicationID is null, this method will default to using the value from the associated meta-data value. The permissions list cannot be null.
protected final void openSessionForPublish(String applicationId, List permissions)
Parâmetro | Descrição |
---|---|
applicationId | The applicationID, can be null |
permissions | The permissions list, cannot be null |
openSessionForPublish(String, List, SessionLoginBehavior, int)
Opens a new session with publish permissions. If either applicationID is null, this method will default to using the value from the associated meta-data value. The permissions list cannot be null.
protected final void openSessionForPublish(String applicationId, List permissions, SessionLoginBehavior behavior, int activityCode)
Parâmetro | Descrição |
---|---|
applicationId | The applicationID, can be null |
permissions | The permissions list, cannot be null |
behavior | The login behavior to use with the session |
activityCode | The activity code to use for the SSO activity |
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)
Parâmetro | Descrição |
---|---|
defaultAudience | The 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()
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 UserSettingsFragment 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)
Parâmetro | Descrição |
---|---|
permissions | The 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 UserSettingsFragment 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)
Parâmetro | Descrição |
---|---|
permissions | The 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)
Parâmetro | Descrição |
---|---|
permissions | The 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)
Parâmetro | Descrição |
---|---|
permissions | The 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)
Parâmetro | Descrição |
---|---|
loginBehavior | The 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()
setOnErrorListener(OnErrorListener)
Sets an OnErrorListener for this instance of UserSettingsFragment to call into when certain exceptions occur.
public void setOnErrorListener(OnErrorListener onErrorListener)
Parâmetro | Descrição |
---|---|
onErrorListener | The listener object to set |
getOnErrorListener()
Returns the current OnErrorListener for this instance of UserSettingsFragment.
public OnErrorListener getOnErrorListener()
setSessionStatusCallback(StatusCallback)
Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.
public void setSessionStatusCallback(StatusCallback callback)
Parâmetro | Descrição |
---|---|
callback | The 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()