I'm following this guide to create an app which sends an image to Facebook messenger.
String mimeType = "image/png";
Uri contentUri = Uri.parse("android.resource://com.test.test/drawable/foobar");
String metadata = "{ \"name\": \"baz\" }";
ShareToMessengerParams params = ShareToMessengerParams.newBuilder(contentUri, mimeType).setMetaData(metadata).build();
MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, params);
The code is pretty simple and almost identical to Facebook's own sample code. The image is properly sent to the messenger which recognizes my app to be optimized and supplies the REPLY button. However, I am having trouble getting the metadata sent across. When the REPLY button is pressed, everything that's supposed to be in the extra bundle (EXTRA_IS_REPLY
, EXTRA_THREAD_TOKEN
, EXTRA_PARTICIPANTS
) is sent back to the app but not the metadata. Any help will be greatly appreciated.
Below is a snippet from manifest:
<!-- Activities -->
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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>
<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_20150314"/>
</intent-filter>
</activity>
Ok so here's the workaround for those having the same problem.
If an app posts a same image to Facebook Messenger multiple times, the Messenger treats all but the first image as duplicates and doesn't attach the metadata. (There's an eventual timeout but can't care less to figure out the exact duration)
My workaround is as follows: Every time your app posts to the messenger, make it place a random pixel in a random location to make sure the image's signature changes. I haven't tried but I think changing the alpha value of a pixel will work better in terms of making it less conspicuous to the users.