Java Code Examples for com.facebook.Session#getActiveSession()

The following examples show how to use com.facebook.Session#getActiveSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostActivity.java    From Klyph with MIT License 6 votes vote down vote up
private void handlePublishPost()
{
	pendingAnnounce = false;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingAnnounce = true;
		requestPublishPermissions(this, PERMISSIONS);
		return;
	}

	numTry = 0;
	publishPost();
}
 
Example 2
Source File: StreamFragment.java    From Klyph with MIT License 6 votes vote down vote up
private void handleDeleteCommentAction(Comment comment)
{
	pendingDeleteComment = false;
	pendingComment = comment;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingDeleteComment = true;
		requestPublishPermissions(session);
		return;
	}

	askDeleteComment(comment);
	pendingComment = null;
}
 
Example 3
Source File: EventFragment.java    From Klyph with MIT License 6 votes vote down vote up
private void handleResponseClick(int request)
{
	pendingAnnounce = false;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingAnnounce = true;
		pendingRequest = request;
		requestPublishPermissions(session);
		return;
	}

	sendRequest(request);
}
 
Example 4
Source File: TitledActivity.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public boolean  onCreateOptionsMenu(Menu menu)
{
	// menu.clear();

	if (Session.getActiveSession() != null && Session.getActiveSession().isOpened())
	{
		// menu.add(Menu.NONE, R.id.menu_chat, 7, R.string.menu_chat);
		menu.add(Menu.NONE, R.id.menu_feedback, 7, R.string.menu_feedback);

		/*
		 * if (!KlyphPreferences.hasUserDonated())
		 * {
		 * menu.add(Menu.NONE, R.id.menu_donate, 8, R.string.menu_donate);
		 * }
		 */

		menu.add(Menu.NONE, R.id.menu_settings, 9, R.string.menu_preferences);
		menu.add(Menu.NONE, R.id.menu_logout, 10, R.string.menu_logout);
		return true;
	}

	return false;
}
 
Example 5
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
private void postImageToFacebook() {
    Session session = Session.getActiveSession();
    final Uri uri = (Uri) mExtras.get(Intent.EXTRA_STREAM);
    final String extraText = mPostTextView.getText().toString();
    if (session.isPermissionGranted("publish_actions"))
    {
        Bundle param = new Bundle();

        // Add the image
        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] byteArrayData = stream.toByteArray();
            param.putByteArray("picture", byteArrayData);
        } catch (IOException ioe) {
            // The image that was send through is now not there?
            Assert.assertTrue(false);
        }

        // Add the caption
        param.putString("message", extraText);
        Request request = new Request(session,"me/photos", param, HttpMethod.POST, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                addNotification(getString(R.string.photo_post), response.getGraphObject(), response.getError());

            }
        }, null);
        RequestAsyncTask asyncTask = new RequestAsyncTask(request);
        asyncTask.execute();
        finish();
    }
}
 
Example 6
Source File: FragmentSocialTimeline.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void loginError() {
    Session session = Session.getActiveSession();

    if (session != null && session.isOpened()) {
        session.closeAndClearTokenInformation();
    }
    loginMode = false;
    init();
}
 
Example 7
Source File: MainActivity.java    From Klyph with MIT License 5 votes vote down vote up
private void updateView()
{
	Session session = Session.getActiveSession();

	if (session.isOpened())
	{
		if (sessionInitalized == false && KlyphSession.getSessionUserId() != null)
		{
			endInit();
		}
	}
}
 
Example 8
Source File: SessionTracker.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 9
Source File: TitledActivity.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
	if (Session.getActiveSession() != null && Session.getActiveSession().isOpened())
	{
		menu.add(Menu.NONE, R.id.menu_feedback, 7, R.string.menu_feedback);

		menu.add(Menu.NONE, R.id.menu_settings, 9, R.string.menu_preferences);
		menu.add(Menu.NONE, R.id.menu_logout, 10, R.string.menu_logout);
		return true;
	}

	return false;
}
 
Example 10
Source File: SessionTracker.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
        }
    }
}
 
Example 11
Source File: SessionTracker.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@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);
        }
    }
}
 
Example 12
Source File: SessionTracker.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 13
Source File: StreamButtonBar.java    From Klyph with MIT License 5 votes vote down vote up
private void handleDeleteAction(final IStreamHolder holder, final Stream stream)
{
	pendingDelete = false;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingDelete = true;
		requestPermissions(holder, stream, null);
		return;
	}

	doDeleteAction(holder, stream);
}
 
Example 14
Source File: ImageFragment.java    From Klyph with MIT License 5 votes vote down vote up
private void handlePostComment()
{
	pendingAnnounce = false;
	Session session = Session.getActiveSession();

	List<String> permissions = session.getPermissions();
	if (!permissions.containsAll(PERMISSIONS))
	{
		pendingAnnounce = true;
		requestPublishPermissions(session);
		return;
	}

	postComment();
}
 
Example 15
Source File: TitledActivity.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	setTheme(getCustomTheme());
	KlyphLocale.defineLocale(getBaseContext());

	super.onCreate(savedInstanceState);

	userHasDonated = KlyphPreferences.hasUserDonated();

	setContentView(getLayout());

	KlyphDevice.initDeviceValues(this);

	setAppIconBackToHomeEnabled(true);
	displayBackArrow(true);

	// manageAdView((AdView) findViewById(R.id.ad), LFPA.FREE_VERSION);

	if (!KlyphSession.isLogged())
	{
		logout();
	}
	else if (Session.getActiveSession() == null)
	{
		Session.openActiveSessionFromCache(this);
	}
}
 
Example 16
Source File: FacebookGraphAPIRequestTask.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * This is the method performing all of this Tasks' work. It loops through all of the {@link com.dhsoftware.android.FacebookNewsfeedSample.model.GraphAPIRequest GraphAPIRequest}s and
 * adds all the downloaded items into a list.
 */
@Override
protected Void doInBackground(GraphAPIRequest... params) {
   mItems = new ArrayList<INewsfeedItem>();
   final Session session = Session.getActiveSession();
   for (GraphAPIRequest request : params) {
      Request graphApiRequest = Request.newGraphPathRequest(session, request.getGraphPath(), null);
      graphApiRequest.setParameters(request.getParameters());
      // this call blocks the calling thread, but in this case it's OK, since we're already in a background thread
      // in this way, you can see both uses of making requests to the Facebook API
      Response response = graphApiRequest.executeAndWait();
      // we could also check here that our Session's valid; which is recommended in Facebook's own samples
      // in this sample's case, I check it in MyNewsfeedFragment just before adding the downloaded items to the Adapter
      if (response != null) {
         // if we did get a response, we
         processResponse(response.getGraphObject().getInnerJSONObject());
      }

   }

   // We sort all items we've downloaded from newest to oldest,
   // in this way, the items will fill in naturally to how we display
   // Newsfeed items.
   Collections.sort(mItems, new Comparator<INewsfeedItem>() {
      @Override
      public int compare(INewsfeedItem lhs, INewsfeedItem rhs) {
         DateTime lhsDateTime = new DateTime(lhs.getCreated_Time());
         DateTime rhsDateTime = new DateTime(rhs.getCreated_Time());
         return (lhsDateTime.compareTo(rhsDateTime));
      }
   });

   // this is not the method returning the objects,
   // since we're still running in a background thread
   return null;
}
 
Example 17
Source File: HypFacebookFrag.java    From HypFacebook with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
*
*
* @public
* @return	void
*/
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	_sAppID			= getArguments().getString( APP_ID );
	_aPermissions	= Arrays.asList( getArguments().getString( APP_PERMS ).split("&"));

	trace("onCreate");


      	//_authorize( );



       uiHelper = new UiLifecycleHelper(getActivity( ), callback);
      	uiHelper.onCreate(savedInstanceState);

      	_session = Session.getActiveSession();
       if (!_session.isOpened() && !_session.isClosed() ) {
           _session.openForRead( new Session.OpenRequest(this).setCallback( callback ) );
       } else {
           Session.openActiveSession( getActivity( ), this , true , callback );
       }
}
 
Example 18
Source File: LoginFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(final View v) {

    switch (v.getId()) {

        case R.id.button_facebook_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.FACEBOOK));
            final Session session = Session.getActiveSession();
            if (!session.isOpened() && !session.isClosed()) {
                session.openForRead(new Session.OpenRequest(this)
                                            .setPermissions(Arrays
                                                                    .asList(AppConstants
                                                                                    .FBPERMISSIONS))
                                            .setCallback(this));
            } else {
                Session.openActiveSession(getActivity(), this, true, this);
            }
            break;
        }

        case R.id.button_google_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.GOOGLE));
            ((AuthActivity) getActivity()).getPlusManager().login();
            break;
        }

        case R.id.button_submit: {
            if (isInputValid()) {
                GoogleAnalyticsManager
                        .getInstance()
                        .sendEvent(
                                new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                        .set(ParamKeys.TYPE, ParamValues.EMAIL)
                        );
                login(mEmailEditText.getText().toString(), mPasswordEditText
                        .getText().toString());
            }
            break;
        }

        case R.id.forgot_password: {
            showForgotPasswordDialog();

        }
    }
}
 
Example 19
Source File: SessionTracker.java    From FacebookImageShareIntent with MIT License 2 votes vote down vote up
/**
 * Returns the current Session that's being tracked.
 * 
 * @return the current Session associated with this tracker
 */
public Session getSession() {
    return (session == null) ? Session.getActiveSession() : session;
}
 
Example 20
Source File: SessionTracker.java    From KlyphMessenger with MIT License 2 votes vote down vote up
/**
 * Returns the current Session that's being tracked.
 * 
 * @return the current Session associated with this tracker
 */
public Session getSession() {
    return (session == null) ? Session.getActiveSession() : session;
}