Java 类com.facebook.Session 实例源码

项目:AndroidBackendlessChat    文件:FacebookFragment.java   
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
项目:AndroidBackendlessChat    文件:FriendPickerFragment.java   
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
项目:AndroidBackendlessChat    文件:BFacebookManager.java   
public static  Promise<List<GraphUser>, BError, Void>  getUserFriendList(){

        final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>();


        if (!Session.getActiveSession().getState().isOpened())
        {
            return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        }
        Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                deferred.resolve(users);
            }
        });

        req.executeAsync();

        return deferred.promise();
    }
项目:AndroidBackendlessChat    文件:BFacebookManager.java   
public static void logout(Context ctx){
    userFacebookAccessToken = null;

    if (Session.getActiveSession() != null)
    {
        Session.getActiveSession().closeAndClearTokenInformation();
    }
    else
    {
        if (DEBUG) Timber.e("getActiveSessionIsNull");
        Session session = Session.openActiveSessionFromCache(ctx);

        if (session != null)
            session.closeAndClearTokenInformation();
    }
}
项目:chat-sdk-android-push-firebase    文件:FacebookFragment.java   
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
项目:chat-sdk-android-push-firebase    文件:FriendPickerFragment.java   
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
项目:chat-sdk-android-push-firebase    文件:BFacebookManager.java   
public static  Promise<List<GraphUser>, BError, Void>  getUserFriendList(){

        final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>();


        if (!Session.getActiveSession().getState().isOpened())
        {
            return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        }
        Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                deferred.resolve(users);
            }
        });

        req.executeAsync();

        return deferred.promise();
    }
项目:chat-sdk-android-push-firebase    文件:BFacebookManager.java   
public static void logout(Context ctx){
    userFacebookAccessToken = null;

    if (Session.getActiveSession() != null)
    {
        Session.getActiveSession().closeAndClearTokenInformation();
    }
    else
    {
        if (DEBUG) Timber.e("getActiveSessionIsNull");
        Session session = Session.openActiveSessionFromCache(ctx);

        if (session != null)
            session.closeAndClearTokenInformation();
    }
}
项目:aptoide-client    文件:FragmentSocialTimeline.java   
private void startLogin(GraphUser user, Session session) {
    try {
        loginMode = true;
        Fragment fragment = new FragmentSignIn();
        Bundle args = new Bundle();
        args.putInt(FragmentSignIn.LOGIN_MODE_ARG, LoginActivity.Mode.FACEBOOK.ordinal());
        args.putString(FragmentSignIn.LOGIN_PASSWORD_OR_TOKEN_ARG, session.getAccessToken());
        args.putString(FragmentSignIn.LOGIN_USERNAME_ARG, (String) user.getProperty("email"));
        fragment.setArguments(args);
        getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, "tag").setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();

        Analytics.SocialTimeline.login();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:pedefacil    文件:FbLoginDelegate.java   
public void requestUserData( Session session ) {
    // Request user data and show the results
    Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (user != null) {
               User currentUser = new User();
                currentUser.setUserId(user.getId());
                currentUser.setUserName(user.getUsername());
                currentUser.setFirstName(user.getFirstName());
                currentUser.setLastName(user.getLastName());
                currentUser.setDisplayName(user.getName());
                currentUser.setMail((String) user.getProperty("email"));
                currentUser.setProviderDisplayName("Facebook");
                currentUser.setProvider(PROVIDER_NAME);
               FbLoginDelegate.this.mUserHelper.setCurrentUser(currentUser);
                if ( mUserSessionCallback != null) {
                    mUserSessionCallback.onLogin();
                }
            }
        }
    }).executeAsync();
}
项目:TP-Formation-Android    文件:FacebookFragment.java   
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
项目:house-devs    文件:LoginFragment.java   
/**
 * Changes the UI when an interaction with the Session object occurs with the user.
 * @param session       The current active Session.
 * @param sessionState  The current state of the active Session.
 * @param e             An Exception if there is one.
 */
private void onSessionStateChange(Session session, SessionState sessionState, Exception e) {
    if (sessionState == SessionState.OPENED) {
        Log.d(TAG, "Successful login!");
        new Request(session, "/me", null, HttpMethod.GET, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                JSONObject obj = response.getGraphObject().getInnerJSONObject();
                Log.d(TAG, "Got back " + obj + " from Facebook API.");
                UserSession.getInstance().setFacebookData(obj);
                getUserData();
            }
        }).executeAsync();
    } else if (e != null) { // handle exception

    }
}
项目:BrainStudio    文件:FacebookFragment.java   
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
项目:CallService-Facebook-sample    文件:FbLoginActivity.java   
private boolean ensureOpenSession() {
    if (Session.getActiveSession() == null
            || !Session.getActiveSession().isOpened()) {
        Session.openActiveSession(this, true, PERMISSIONS,
                new Session.StatusCallback() {
                    @Override
                    public void call(Session session, SessionState state,
                                     Exception exception) {
                        onSessionStateChanged(session, state, exception);
                    }
                });
        return false;
    }
    makeMeRequest();
    return true;
}
项目:snake-game-aws    文件:FacebookFragment.java   
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
项目:IPRJapp    文件:Left_Menu.java   
private void sendRequestDialog() {

      Bundle params = new Bundle();
      params.putString("title", "Solicitação de Aplicativo");
      params.putString("message", "Experimente o IPRJapp");
      params.putString("link","https://play.google.com/store/apps/details?id=com.wb.goog.batman.brawler2013");
      params.putString("data",
          "{\"badge_of_awesomeness\":\"1\"," +
          "\"social_karma\":\"5\"}");  

      WebDialog requestsDialog = (
          new WebDialog.RequestsDialogBuilder(this.getActivity(), Session.getActiveSession(), params))
              .setOnCompleteListener(new OnCompleteListener() {

                  @Override
                  public void onComplete(Bundle values, FacebookException error) {
                  }

              })
              .build();
      requestsDialog.show();
  }
项目:UniversalSocialLoginAndroid    文件:FacebookLoginActivity.java   
private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
        makeMeRequest();
        // textInstructionsOrLink.setText(URL_PREFIX_FRIENDS +
        // session.getAccessToken());

        // buttonLoginLogout.setText("Logout");
        // buttonLoginLogout.setOnClickListener(new OnClickListener() {
        // public void onClick(View view) { onClickLogout(); }
        // });
    } else {
        onClickLogin();
        // textInstructionsOrLink.setText("Please login");
        // buttonLoginLogout.setText("Login");
        // buttonLoginLogout.setOnClickListener(new OnClickListener() {
        // public void onClick(View view) { onClickLogin(); }
        // });
    }

}
项目:guitar_guy    文件:FacebookProfileConnector.java   
@Override
public void connect(Activity activity)
{
    Session session = Session.getActiveSession();

    // TODO: I think we should validate the session here, but to what
    // extent?

    MadFacebookStatusCallback statusCallback =
            new MadFacebookStatusCallback();

    // Check if the session is already open.
    if (!session.isOpened() && !session.isClosed())
    {
        OpenRequest openRequest = new OpenRequest(activity);
        session.openForRead(openRequest
                .setCallback(statusCallback));
    }
    else
    {
        Session.openActiveSession(activity, true,
                statusCallback);
    }

}
项目:CallService-Facebook-sample    文件:UserHome.java   
public void populateContact() {
    final Session session = Session.getActiveSession();
    new Request(session, "/me/friends", null, HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {

                    // Process the returned response
                    GraphObject graphObject = response.getGraphObject();
                    if (graphObject != null) {
                        // Check if there is extra data
                        if (graphObject.getProperty("data") != null) {
                                JSONArray arrayObject = (JSONArray) graphObject
                                        .getProperty("data");

                                int count = arrayObject.length();
                                if(count == 0)
                                    hasAppFriends = false;
                                // Ensure the user has at least one friend
                                //session.close();
                        }
                    }
                }

            }).executeAsync();
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
/**
 * Constructs a SessionTracker to track the Session object passed in.
 * If the Session is null, then it will track the active Session instead.
 * 
 * @param context the context object.
 * @param callback the callback to use whenever the Session's state changes
 * @param session the Session object to track
 * @param startTracking whether to start tracking the Session right away
 */
public SessionTracker(Context context, Session.StatusCallback callback, Session session, boolean startTracking) {
    this.callback = new CallbackWrapper(callback);
    this.session = session;
    this.receiver = new ActiveSessionBroadcastReceiver();
    this.broadcastManager = LocalBroadcastManager.getInstance(context);

    if (startTracking) {
        startTracking();
    }
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
/**
 * Set the Session object to track.
 * 
 * @param newSession the new Session object to track
 */
public void setSession(Session newSession) {
    if (newSession == null) {
        if (session != null) {
            // We're current tracking a Session. Remove the callback
            // and start tracking the active Session.
            session.removeCallback(callback);
            session = null;
            addBroadcastReceiver();
            if (getSession() != null) {
                getSession().addCallback(callback);
            }
        }
    } else {
        if (session == null) {
            // We're currently tracking the active Session, but will be
            // switching to tracking a different Session object.
            Session activeSession = Session.getActiveSession();
            if (activeSession != null) {
                activeSession.removeCallback(callback);
            }
            broadcastManager.unregisterReceiver(receiver);
        } else {
            // We're currently tracking a Session, but are now switching 
            // to a new Session, so we remove the callback from the old 
            // Session, and add it to the new one.
            session.removeCallback(callback);
        }
        session = newSession;
        session.addCallback(callback);
    }
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
/**
 * Stop tracking the Session and remove any callbacks attached
 * to those sessions.
 */
public void stopTracking() {
    if (!isTracking) {
        return;
    }
    Session session = getSession();
    if (session != null) {
        session.removeCallback(callback);
    }
    broadcastManager.unregisterReceiver(receiver);
    isTracking = false;
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
private void addBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Session.ACTION_ACTIVE_SESSION_SET);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET);

    // Add a broadcast receiver to listen to when the active Session
    // is set or unset, and add/remove our callback as appropriate    
    broadcastManager.registerReceiver(receiver, filter);
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (Session.ACTION_ACTIVE_SESSION_SET.equals(intent.getAction())) {
        Session session = Session.getActiveSession();
        if (session != null) {
            session.addCallback(SessionTracker.this.callback);
        }
    }
}
项目:AndroidBackendlessChat    文件:SessionTracker.java   
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Gets the current Session.
 * 
 * @return the current Session object.
 */
protected final Session getSession() {
    if (sessionTracker != null) {
        return sessionTracker.getSession();
    }
    return null;
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Gets the access token associated with the current session or null if no 
 * session has been created.
 * 
 * @return the access token
 */
protected final String getAccessToken() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        return (currentSession != null) ? currentSession.getAccessToken() : null;
    }
    return null;
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Gets the date at which the current session will expire or null if no session 
 * has been created.
 * 
 * @return the date at which the current session will expire
 */
protected final Date getExpirationDate() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        return (currentSession != null) ? currentSession.getExpirationDate() : null;
    }
    return null;
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Closes the current session.
 */
protected final void closeSession() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            currentSession.close();
        }
    }
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Closes the current session as well as clearing the token cache.
 */
protected final void closeSessionAndClearTokenInformation() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            currentSession.closeAndClearTokenInformation();
        }
    }
}
项目:AndroidBackendlessChat    文件:FacebookFragment.java   
/**
 * Gets the permissions associated with the current session or null if no session 
 * has been created.
 * 
 * @return the permissions associated with the current session
 */
protected final List<String> getSessionPermissions() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getPermissions() : null;
    }
    return null;
}
项目:AndroidBackendlessChat    文件:FriendPickerFragment.java   
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
项目:AndroidBackendlessChat    文件:BFacebookManager.java   
/** Re authenticate after session state changed.*/
public static Promise<Object, BError, Void> onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (DEBUG) Timber.i("Session changed state");

    // If we can start the login process with no errors this promise wont be used. 
    // The returned promise will be from the loginWithFacebook.
    Deferred<Object, BError, Void> deferred = new DeferredObject<>();

    if (exception != null)
    {
        exception.printStackTrace();
        if (exception instanceof FacebookOperationCanceledException)
        {
            deferred.reject(new BError(BError.Code.EXCEPTION, exception));
            return deferred.promise();
        }
    }

    if (state.isOpened()) {
        if (DEBUG) Timber.i("Session is open.");

        // We will need this session later to make request.
        userFacebookAccessToken = Session.getActiveSession().getAccessToken();

        return loginWithFacebook();

    } else if (state.isClosed()) {
        // Logged out of Facebook
        if (DEBUG) Timber.i("Session is closed.");
        deferred.reject(new BError(BError.Code.SESSION_CLOSED, "Facebook session is closed."));
    }


    return deferred.promise();
}
项目:AndroidBackendlessChat    文件:BFacebookManager.java   
public static Promise<GraphObject, BError, Void> getUserDetails(){

        final Deferred<GraphObject, BError, Void> deferred = new DeferredObject<>();

        if (Session.getActiveSession().getState().isOpened())
        {
            // Request user data and show the results
            Request.newMeRequest(Session.getActiveSession(), new Request.GraphUserCallback()
            {
                @Override
                public void onCompleted(GraphUser user, Response response)
                {
                    if (response != null)
                    {
                        try
                        {
                            deferred.resolve(user);
                        }
                        catch (Exception e)
                        {
                            deferred.reject(BError.getExceptionError(e));
                        }

                    }
                }
            }).executeAsync();
        } else deferred.reject(new BError(BError.Code.SESSION_CLOSED));

        return deferred.promise();
    }
项目:AndroidBackendlessChat    文件:ChatSDKBaseActivity.java   
protected void onSessionStateChange(Session session, final SessionState state, Exception exception){
    BFacebookManager.onSessionStateChange(session, state, exception)
            .fail(new FailCallback<BError>() {
                @Override
                public void onFail(BError bError) {
                    if (DEBUG) Timber.e("onDoneWithError. Error: %s", bError.message);
                    // Facebook session is closed so we need to disconnect from firebase.
                    getNetworkAdapter().logout();
                    startLoginActivity(true);
                }
            });
}
项目:AndroidBackendlessChat    文件:ChatSDKAbstractLoginActivity.java   
public void onSessionStateChange(Session session, SessionState state, Exception exception){

        if (!getNetworkAdapter().facebookEnabled())
        {
            return;
        }

        if (exception != null)
        {
            exception.printStackTrace();
            if (exception instanceof FacebookOperationCanceledException)
            {
                return;
            }
        }else showOrUpdateProgDialog(getString(R.string.authenticating));

        BFacebookManager.onSessionStateChange(session, state, exception).done(new DoneCallback<Object>() {
            @Override
            public void onDone(Object o) {
                if (DEBUG) Timber.i("Connected to facebook");
                afterLogin();
            }
        }).fail(new FailCallback<BError>() {
            @Override
            public void onFail(BError bError) {
                if (DEBUG) Timber.i(TAG, "Error connecting to Facebook");
//                Toast.makeText(LoginActivity.this, "Failed connect to facebook.", Toast.LENGTH_SHORT).show();
                showAlertToast( getString(R.string.login_activity_facebook_connection_fail_toast) );
                BFacebookManager.logout(ChatSDKAbstractLoginActivity.this);
                dismissProgDialog();
            }
        });
    }
项目:chat-sdk-android-push-firebase    文件:SessionTracker.java   
/**
 * Constructs a SessionTracker to track the Session object passed in.
 * If the Session is null, then it will track the active Session instead.
 * 
 * @param context the context object.
 * @param callback the callback to use whenever the Session's state changes
 * @param session the Session object to track
 * @param startTracking whether to start tracking the Session right away
 */
public SessionTracker(Context context, Session.StatusCallback callback, Session session, boolean startTracking) {
    this.callback = new CallbackWrapper(callback);
    this.session = session;
    this.receiver = new ActiveSessionBroadcastReceiver();
    this.broadcastManager = LocalBroadcastManager.getInstance(context);

    if (startTracking) {
        startTracking();
    }
}
项目:chat-sdk-android-push-firebase    文件:SessionTracker.java   
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}