Android SDK Version
  • java.lang.Object
    • com.facebook.messenger.MessengerUtils

public class MessengerUtils
extends java.lang.Object
Utilities for Messenger Content Platform.
Applications should specify the app id in their manifest or call FacebookSdk.setApplicationId(String) } in their application startup path. For specifying in the manifest, add a meta tag in your <application> tag.
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="YOUR_APP_ID"/>
   
When sharing to Messenger, apps should call the shareToMessenger(Activity, int, com.facebook.messenger.ShareToMessengerParams) method. For example,
     ShareToMessengerParams params = ShareToMessengerParams.newBuilder(uri, "image/*")
         .setMetaData(metaData)
         .build();
     MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, params);
   
To handle receiving a composer shortcut or reply intent from Messenger, apps should put the following intent filter in their manifest for the activity that receives the intent:
           <intent-filter>
             <action android:name="android.intent.action.PICK" />
             <category android:name="android.intent.category.DEFAULT"/>
             <category android:name="com.facebook.orca.category.PLATFORM_THREAD_20150311"/>
           </intent-filter>
   
When handling the intent, then call getMessengerThreadParamsForIntent(Intent) to receive the parameters for messenger. When the user has clicked the Send button to send the content to Messenger, then call finishShareToMessenger(Activity, com.facebook.messenger.ShareToMessengerParams) to return the data back to Messenger.
Field Summary
Modifier and TypeField and Description
static java.lang.StringEXTRA_APP_ID 
static java.lang.StringEXTRA_EXTERNAL_URI 
static java.lang.StringEXTRA_IS_COMPOSE 
static java.lang.StringEXTRA_IS_REPLY 
static java.lang.StringEXTRA_METADATA 
static java.lang.StringEXTRA_PARTICIPANTS 
static java.lang.StringEXTRA_PROTOCOL_VERSION 
static java.lang.StringEXTRA_REPLY_TOKEN_KEY 
static java.lang.StringEXTRA_THREAD_TOKEN_KEY 
static java.lang.StringORCA_THREAD_CATEGORY_20150314 
static java.lang.StringPACKAGE_NAME 
static intPROTOCOL_VERSION_20150314 
Constructor Summary
Constructor and Description
MessengerUtils() 
Method Summary
Modifier and TypeMethod and Description
static voidfinishShareToMessenger(Activity activity, ShareToMessengerParams shareToMessengerParams)
Finishes the activity and returns the media item the user picked to Messenger.
static MessengerThreadParamsgetMessengerThreadParamsForIntent(Intent intent)
When handling an Intent from Messenger, call this to parse the parameters of the intent.
static booleanhasMessengerInstalled(Context context)
Checks whether any version of messenger is installed.
static voidopenMessengerInPlayStore(Context context)
Opens the play store to install Messenger.
static voidshareToMessenger(Activity activity, int requestCode, ShareToMessengerParams shareToMessengerParams)
Starts an intent to share a piece of media on Messenger using the messenger content platform.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail

PACKAGE_NAME

public static final java.lang.String PACKAGE_NAME

EXTRA_PROTOCOL_VERSION

public static final java.lang.String EXTRA_PROTOCOL_VERSION

EXTRA_APP_ID

public static final java.lang.String EXTRA_APP_ID

EXTRA_REPLY_TOKEN_KEY

public static final java.lang.String EXTRA_REPLY_TOKEN_KEY

EXTRA_THREAD_TOKEN_KEY

public static final java.lang.String EXTRA_THREAD_TOKEN_KEY

EXTRA_METADATA

public static final java.lang.String EXTRA_METADATA

EXTRA_EXTERNAL_URI

public static final java.lang.String EXTRA_EXTERNAL_URI

EXTRA_PARTICIPANTS

public static final java.lang.String EXTRA_PARTICIPANTS

EXTRA_IS_REPLY

public static final java.lang.String EXTRA_IS_REPLY

EXTRA_IS_COMPOSE

public static final java.lang.String EXTRA_IS_COMPOSE

PROTOCOL_VERSION_20150314

public static final int PROTOCOL_VERSION_20150314

ORCA_THREAD_CATEGORY_20150314

public static final java.lang.String ORCA_THREAD_CATEGORY_20150314
Constructor Detail

MessengerUtils

public MessengerUtils()
Method Detail

shareToMessenger

public static void shareToMessenger(Activity activity,
                                    int requestCode,
                                    ShareToMessengerParams shareToMessengerParams)
Starts an intent to share a piece of media on Messenger using the messenger content platform.
Parameters:
activity - the activity sharing the content
requestCode - a unique request code for Activity#startActivityForResult
shareToMessengerParams - parameters for what to share

getMessengerThreadParamsForIntent

public static MessengerThreadParams getMessengerThreadParamsForIntent(Intent intent)
When handling an Intent from Messenger, call this to parse the parameters of the intent.
Parameters:
intent - the intent of the activity
Returns:
a MessengerThreadParams or null if this intent wasn't recognized as a request from Messenger to share.

finishShareToMessenger

public static void finishShareToMessenger(Activity activity,
                                          ShareToMessengerParams shareToMessengerParams)
Finishes the activity and returns the media item the user picked to Messenger.
Parameters:
activity - the activity that received the original intent from Messenger
shareToMessengerParams - parameters for what to share

hasMessengerInstalled

public static boolean hasMessengerInstalled(Context context)
Checks whether any version of messenger is installed.
Parameters:
context - an android context
Returns:
whether any version of messenger is installed

openMessengerInPlayStore

public static void openMessengerInPlayStore(Context context)
Opens the play store to install Messenger.
Parameters:
context - an android context.