Class FacebookHelper


  • public class FacebookHelper
    extends java.lang.Object
    Helper class for Facebook calls. In order to initialize Facebook login your activity/fragment, make sure you call the listener FacebookLoginCallBack, also call FacebookHelper.onActivityResult(requestCode,resultCode,data), onActivityResult. In order to share Facebook posts, make sure you call the listener FacebookShareCallBack on your activity/fragment and FacebookHelper.initializeShareToFacebook() Helper class for Facebook calls
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static com.facebook.CallbackManager mFbCallbackManager  
      protected static com.facebook.login.widget.LoginButton mLoginButton  
    • Constructor Summary

      Constructors 
      Constructor Description
      FacebookHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void initializeFacebookButtonLogin​(android.app.Activity activity, int facebookLoginButtonId, java.lang.String... permissionList)
      Initializes facebook button login on Activity.
      static void initializeFacebookButtonLogin​(androidx.fragment.app.Fragment fragment, android.view.View view, android.content.Context context, int facebookLoginButtonId, java.lang.String... permissionList)
      Initializes facebook button login on a fragment Take note call FacebookSdk.sdkIntialized first before super.onCreate on your activity.
      static void initializeFacebookLogin​(android.app.Activity activity, java.lang.String... permissionList)
      Initializes Facebook Login with the stated permissions Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data), on onActivityResult
      static void initializeFacebookLogin​(androidx.fragment.app.Fragment fragment, java.lang.String... permissionList)
      Initializes Facebook Login with the stated permissions Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data), on onActivityResult
      static boolean isNativeAppInstalled()
      Check if the native Facebook app is installed.
      static void onActivityResult​(int requestCode, int resultCode, android.content.Intent data)
      Make sure to call this on your onActivity Result
      static void postPhoto​(android.app.Activity activity, android.graphics.Bitmap resource)
      Post a photo on facebook Call FacebookHelper.initializeShareToFacebook() first on your activity/fragment
      static void postViaShareApi​(com.facebook.share.model.SharePhotoContent photoContent)
      Share a photocontent on facebook
      static void shareObject​(android.app.Activity activity, java.lang.String targetUrl, java.lang.String heading, java.lang.String body, java.lang.String imageUrl)
      Share Url on Facebook
      static void shareObject​(android.app.Activity activity, java.lang.String type, java.lang.String title, java.lang.String imageUrl, java.lang.String actionType, java.lang.String propertyName)
      Share an object to Facebook.
      static void shareObject​(androidx.fragment.app.Fragment fragment, java.lang.String targetUrl, java.lang.String heading, java.lang.String body, java.lang.String imageUrl)
      Share Url on Facebook
      static boolean shareUrl​(android.app.Activity activity, android.net.Uri uri)
      Share link only to Facebook.
      static boolean shareUrl​(androidx.fragment.app.Fragment fragment, android.net.Uri uri)
      Share link only to Facebook.
      static boolean shareVideo​(android.app.Activity activity, android.net.Uri mSelectedVideoUri)
      Share video to facebook.
      static boolean shareVideo​(androidx.fragment.app.Fragment fragment, android.net.Uri mSelectedVideoUri)
      Share video to facebook.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mLoginButton

        protected static com.facebook.login.widget.LoginButton mLoginButton
      • mFbCallbackManager

        protected static com.facebook.CallbackManager mFbCallbackManager
    • Constructor Detail

      • FacebookHelper

        public FacebookHelper()
    • Method Detail

      • isNativeAppInstalled

        public static boolean isNativeAppInstalled()
        Check if the native Facebook app is installed.
        Returns:
        true if Facebook app is installed, false otherwise
      • initializeFacebookButtonLogin

        public static void initializeFacebookButtonLogin​(android.app.Activity activity,
                                                         @IdRes
                                                         int facebookLoginButtonId,
                                                         java.lang.String... permissionList)
        Initializes facebook button login on Activity. Take note call FacebookSdk.sdkIntialized first before calling super.onCreate on your activity. In this order: FacebookSdk.sdkInitialize(this); super.onCreate(savedInstanceState); FacebookHelper.initializeFacebookButtonLogin(LoginActivity.this); Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data); on onActivityResult

        Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment

        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        facebookLoginButtonId - resource id of facebook button
        permissionList - permissionList list of permissions from FacebookHelper.Permissions
      • initializeFacebookButtonLogin

        public static void initializeFacebookButtonLogin​(androidx.fragment.app.Fragment fragment,
                                                         android.view.View view,
                                                         android.content.Context context,
                                                         @IdRes
                                                         int facebookLoginButtonId,
                                                         java.lang.String... permissionList)
        Initializes facebook button login on a fragment Take note call FacebookSdk.sdkIntialized first before super.onCreate on your activity. Also this call must be after the super.onCreate. In this order: FacebookSdk.sdkInitialize(this); super.onCreate(savedInstanceState); FacebookHelper.initializeFacebookButtonLogin(LoginActivity.this); Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data), on onActivityResult

        Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment

        Parameters:
        fragment - where FacebookHelper.FacebookLoginCallBack is implemented
        view - view where the fb_sign_in_button can be found
        context - used to get resources
        facebookLoginButtonId - resource id of facebook button
        permissionList - permissionList list of permissions from FacebookHelper.Permissions
      • initializeFacebookLogin

        public static void initializeFacebookLogin​(android.app.Activity activity,
                                                   java.lang.String... permissionList)
        Initializes Facebook Login with the stated permissions Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data), on onActivityResult
        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        permissionList - permissionList list of permissions from FacebookHelper.Permissions
      • initializeFacebookLogin

        public static void initializeFacebookLogin​(androidx.fragment.app.Fragment fragment,
                                                   java.lang.String... permissionList)
        Initializes Facebook Login with the stated permissions Make sure to implement FacebookHelper.FacebookLoginCallBack on your activity/fragment Also call: FacebookHelper.onActivityResult(requestCode,resultCode,data), on onActivityResult
        Parameters:
        fragment - where FacebookHelper.FacebookLoginCallBack is implemented
        permissionList - permissionList list of permissions from FacebookHelper.Permissions
      • shareObject

        public static void shareObject​(android.app.Activity activity,
                                       java.lang.String type,
                                       java.lang.String title,
                                       java.lang.String imageUrl,
                                       java.lang.String actionType,
                                       java.lang.String propertyName)
        Share an object to Facebook. Does not need to call FacebookHelper.initializeShareToFacebook() or add FacebookShareCallback listener
        Parameters:
        activity - where dialog is attached
        type - value to store under og:type
        title - value to store under og:title
        imageUrl - value to store under og:image
        actionType - action given
        propertyName - preview property name
      • shareObject

        public static void shareObject​(android.app.Activity activity,
                                       java.lang.String targetUrl,
                                       java.lang.String heading,
                                       java.lang.String body,
                                       java.lang.String imageUrl)
        Share Url on Facebook
        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        targetUrl - url link to share
        heading - title of the URL link to be shared on facebook
        body - the content description for the url link to be shared on facebook
        imageUrl - image to be shared on facebook together with the url
      • shareObject

        public static void shareObject​(androidx.fragment.app.Fragment fragment,
                                       java.lang.String targetUrl,
                                       java.lang.String heading,
                                       java.lang.String body,
                                       java.lang.String imageUrl)
        Share Url on Facebook
        Parameters:
        fragment - where FacebookHelper.FacebookLoginCallBack is implemented
        targetUrl - url link to share
        heading - title of the URL link to be shared on facebook
        body - the content description for the url link to be shared on facebook
        imageUrl - image to be shared on facebook together with the url
      • shareUrl

        public static boolean shareUrl​(@NonNull
                                       android.app.Activity activity,
                                       android.net.Uri uri)
        Share link only to Facebook. Call FacebookHelper.initializeShareToFacebook() first on your activity
        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        uri - url link to share
        Returns:
        true if share is successful, else false
      • shareUrl

        public static boolean shareUrl​(@NonNull
                                       androidx.fragment.app.Fragment fragment,
                                       android.net.Uri uri)
        Share link only to Facebook. Call FacebookHelper.initializeShareToFacebook() first on your fragment
        Parameters:
        fragment - where FacebookHelper.FacebookLoginCallBack is implemented
        uri - url link to share
        Returns:
        true if share is successful, else false
      • shareVideo

        public static boolean shareVideo​(android.app.Activity activity,
                                         android.net.Uri mSelectedVideoUri)
        Share video to facebook. Call FacebookHelper.initializeShareToFacebook() first on your activity
        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        mSelectedVideoUri - video url to share
        Returns:
        true if share is successful, else false
      • shareVideo

        public static boolean shareVideo​(androidx.fragment.app.Fragment fragment,
                                         android.net.Uri mSelectedVideoUri)
        Share video to facebook. Call FacebookHelper.initializeShareToFacebook() first on your fragment
        Parameters:
        fragment - where FacebookHelper.FacebookLoginCallBack is implemented
        mSelectedVideoUri - video url to share
        Returns:
        true if share is successful, else false
      • postPhoto

        public static void postPhoto​(android.app.Activity activity,
                                     android.graphics.Bitmap resource)
        Post a photo on facebook Call FacebookHelper.initializeShareToFacebook() first on your activity/fragment
        Parameters:
        activity - where FacebookHelper.FacebookLoginCallBack is implemented
        resource - photo to share on facebook
      • postViaShareApi

        public static void postViaShareApi​(com.facebook.share.model.SharePhotoContent photoContent)
        Share a photocontent on facebook
        Parameters:
        photoContent - configured SharePhotoContent
      • onActivityResult

        public static void onActivityResult​(int requestCode,
                                            int resultCode,
                                            android.content.Intent data)
        Make sure to call this on your onActivity Result
        Parameters:
        requestCode - identify source of result
        resultCode - code returned by child activity
        data - extra data passed