Reputation: 3868
I have updated the dependency of Facebook SDK to 4.1.0. They changed a lot and now I cannot find a way to share text and image with Messenger.
Before updating the sdk I was using:
FacebookDialog.MessageDialogBuilder builder = new FacebookDialog.MessageDialogBuilder(this)
.setName(linkName)
.setDescription(description)
.setLink(webLink)
.setPicture(pictureLink);
FacebookDialog dialog = builder.build();
dialog.present();
Now looks like I can only share images.
String mimeType = "image/jpeg";
ShareToMessengerParams shareToMessengerParams =
ShareToMessengerParams.newBuilder(contentUri, mimeType)
.build();
MessengerUtils.shareToMessenger(
this,
REQUEST_CODE_SHARE_TO_MESSENGER,
shareToMessengerParams);
Can anyone explain a equivalent way to share text and image as before 4.1.0 please?
Upvotes: 4
Views: 3920
Reputation: 2134
After I saw everything is deprecated in my case I only need to share 2 images, so the intent method works without Facebook SDK.
"String pack" is the messenger package name, can be one of both :
Messenger: com.facebook.orca
Messenger Lite: com.facebook.mlite
public void shareToOtherAppByPackage(Context context, String pack, Bitmap bitmap1,Bitmap bitmap2) {
try {
ByteArrayOutputStream bytes1 = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, bytes1);
String path1 = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap1, "front", null);
Uri imageUri1 = Uri.parse(path1);
ByteArrayOutputStream bytes2 = new ByteArrayOutputStream();
bitmap2.compress(Bitmap.CompressFormat.JPEG, 100, bytes2);
String path2 = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap2, "back", null);
Uri imageUri2 = Uri.parse(path2);
//PackageManager pm = context.getPackageManager();
//PackageInfo info = pm.getPackageInfo(pack, PackageManager.GET_META_DATA);
ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("image/*");
shareIntent.setPackage(pack);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
//waIntent.putExtra(Intent.EXTRA_TEXT, pack); // adds text to share
context.startActivity(Intent.createChooser(shareIntent , context.getString(R.string.share_with)));
}
catch (Exception e) {
Toast.makeText(context, context.getString(R.string.app_share_not_installed), Toast.LENGTH_SHORT).show();
}
}
Upvotes: 0
Reputation: 3868
I found out that there is a similar way to share on Facebook which works also for Messenger.
Here is the code
ShareLinkContent.Builder shareLinkContentBuilder = new ShareLinkContent.Builder()
.setContentTitle(contentTitle)
.setContentDescription(contentDescription)
.setContentUrl(Uri.parse(url));
shareLinkContentBuilder.setImageUrl(Uri.parse(imageUrl));
MessageDialog messageDialog = new MessageDialog(activity);
messageDialog.registerCallback(callbackManager, callback);
messageDialog.show(shareLinkContentBuilder.build());
The relative doc is under Sharing section and not Messenger one https://developers.facebook.com/docs/sharing/android
Upvotes: 8