Facebook Messenger SDK for Android: URL sharing failed

I need to use the Facebook Messenger SDK in an Android app. I want to send the url as text. Since ShareToMessengerParams is too limited, I had to manually create an intent, as shown at https://developers.facebook.com/docs/messenger/android#integration_with_intents :

private static final String EXTRA_PROTOCOL_VERSION = "com.facebook.orca.extra.PROTOCOL_VERSION";
private static final String EXTRA_APP_ID = "com.facebook.orca.extra.APPLICATION_ID";
private static final int PROTOCOL_VERSION = 20150314;
private static final String YOUR_APP_ID = "[YOUR_FACEBOOK_APP_ID]";
private static final int SHARE_TO_MESSENGER_REQUEST_CODE = 1;

...

String mimeType = "text/plain";

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_TEXT, [MY_STRING_URL]);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);

activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);

Failure:

E/AndroidRuntime( 2429): FATAL EXCEPTION: main

E/AndroidRuntime( 2429): java.lang.ClassCastException: com.facebook.messaging.sharing.f cannot be cast to com.facebook.messaging.sharing.bs

E/AndroidRuntime( 2429):    at com.facebook.messaging.sharing.cz.a(ShareLauncherActivity.java:294)

E/AndroidRuntime( 2429):    at com.facebook.messaging.sharing.cz.onSuccess(ShareLauncherActivity.java:286)

E/AndroidRuntime( 2429):    at com.google.common.f.a.q.run(Futures.java:1231)

E/AndroidRuntime( 2429):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)

E/AndroidRuntime( 2429):    at com.facebook.common.executors.dv.run(WrappingExecutorService.java:77)

E/AndroidRuntime( 2429):    at android.os.Handler.handleCallback(Handler.java:615)

E/AndroidRuntime( 2429):    at android.os.Handler.dispatchMessage(Handler.java:92)

E/AndroidRuntime( 2429):    at android.os.Looper.loop(Looper.java:137)

E/AndroidRuntime( 2429):    at android.app.ActivityThread.main(ActivityThread.java:4745)

E/AndroidRuntime( 2429):    at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 2429):    at java.lang.reflect.Method.invoke(Method.java:511)

E/AndroidRuntime( 2429):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

E/AndroidRuntime( 2429):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

E/AndroidRuntime( 2429):    at dalvik.system.NativeStart.main(Native Method)

W/ActivityManager(  312):   Force finishing activity com.facebook.orca/com.facebook.messaging.sharing.ShareLauncherActivity

If I add:

intent.putExtra(Intent.EXTRA_STREAM, contentUri);

it does not crash, but since my URL is just a link and does not point to a file, I get various errors: the content cannot be found or, if I put a fake contentUri, the real URL I want to share is not activated when I click . If I remove:

intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);

, , ( ), "" Facebook Messenger.

- , "" ""?

+4

Source: https://habr.com/ru/post/1616898/


All Articles