public static void finishShareToMessenger(Activity activity,ShareToMessengerParams shareToMessengerParams){
  Intent originalIntent=activity.getIntent();
  Set<String> categories=originalIntent.getCategories();
  if (categories == null) {
    activity.setResult(Activity.RESULT_CANCELED,null);
    activity.finish();
    return;
  }
  if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
    Bundle appLinkExtras=AppLinks.getAppLinkExtras(originalIntent);
    Intent resultIntent=new Intent();
    if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
      resultIntent.putExtra(EXTRA_PROTOCOL_VERSION,MessengerUtils.PROTOCOL_VERSION_20150314);
      String threadToken=appLinkExtras.getString(MessengerUtils.EXTRA_THREAD_TOKEN_KEY);
      resultIntent.putExtra(EXTRA_THREAD_TOKEN_KEY,threadToken);
    }
 else {
      throw new RuntimeException();
    }
    resultIntent.setDataAndType(shareToMessengerParams.uri,shareToMessengerParams.mimeType);
    resultIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    resultIntent.putExtra(EXTRA_APP_ID,FacebookSdk.getApplicationId());
    resultIntent.putExtra(EXTRA_METADATA,shareToMessengerParams.metaData);
    resultIntent.putExtra(EXTRA_EXTERNAL_URI,shareToMessengerParams.externalUri);
    activity.setResult(Activity.RESULT_OK,resultIntent);
    activity.finish();
  }
 else {
    activity.setResult(Activity.RESULT_CANCELED,null);
    activity.finish();
  }
}

public static void finishShareToMessenger ( Activity activity , ShareToMessengerParams shareToMessengerParams ) { Intent originalIntent = activity . getIntent ( ) ; Set < String > categories = originalIntent . getCategories ( ) ; if ( categories == null ) { activity . setResult ( Activity . RESULT_CANCELED , null ) ; activity . finish ( ) ; return ; } if ( categories . contains ( ORCA_THREAD_CATEGORY_20150314 ) ) { Bundle appLinkExtras = AppLinks . getAppLinkExtras ( originalIntent ) ; Intent resultIntent = new Intent ( ) ; if ( categories . contains ( ORCA_THREAD_CATEGORY_20150314 ) ) { resultIntent . putExtra ( EXTRA_PROTOCOL_VERSION , MessengerUtils . PROTOCOL_VERSION_20150314 ) ; String threadToken = appLinkExtras . getString ( MessengerUtils . EXTRA_THREAD_TOKEN_KEY ) ; resultIntent . putExtra ( EXTRA_THREAD_TOKEN_KEY , threadToken ) ; } else { throw new RuntimeException ( ) ; } resultIntent . setDataAndType ( shareToMessengerParams . uri , shareToMessengerParams . mimeType ) ; resultIntent . setFlags ( Intent . FLAG_GRANT_READ_URI_PERMISSION ) ; resultIntent . putExtra ( EXTRA_APP_ID , FacebookSdk . getApplicationId ( ) ) ; resultIntent . putExtra ( EXTRA_METADATA , shareToMessengerParams . metaData ) ; resultIntent . putExtra ( EXTRA_EXTERNAL_URI , shareToMessengerParams . externalUri ) ; activity . setResult ( Activity . RESULT_OK , resultIntent ) ; activity . finish ( ) ; } else { activity . setResult ( Activity . RESULT_CANCELED , null ) ; activity . finish ( ) ; } }
finishes the activity and returns the media item the user picked to messenger .
