Forum Xamarin Xamarin.Forms

Open Facebook messenger

DimChrisDimChris USMember ✭✭✭✭

Hello developers, is there any way which i can open facebook messenger(For sending message in specific name) from xamarin forms?

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    The current url scheme of Facebook messeger is fb-messenger-public://user-thread/ID .

    Try to launch the app using Xamarin.Essentials: Launcher

           await Launcher.TryOpenAsync("fb-messenger-public://user-thread/ID");
    

    Refer to

    https://docs.microsoft.com/en-us/xamarin/essentials/launcher?tabs=android.
    https://stackoverflow.com/a/32060864/8187800.

  • DimChrisDimChris USMember ✭✭✭✭

    Thank you ColeX. Does it work also for android? i tried the code below in android but messenger does not show up. Also how can i find user-thread and id? It looks like m.me/dio.xxx923 ?

  • ColeXColeX Member, Xamarin Team Xamurai

    For android you could try fb-messenger://user/%s , %s is the numeric fb user id , you should be able to find the id in user profile page .

    Check https://stackoverflow.com/questions/25467445/custom-uri-schemes-for-the-facebook-messenger.

  • DimChrisDimChris USMember ✭✭✭✭

    Thank you ColeX, in android works perfectly. It looks like

    await Launcher.TryOpenAsync("fb-messenger://m.me/dio.923");

    Unfortunately in ios it does'n work.
    I also tried

    await Launcher.TryOpenAsync("fb-messenger-public://m.me/dio.923");

  • ColeXColeX Member, Xamarin Team Xamurai

    @DimChris said:
    Thank you ColeX, in android works perfectly. It looks like

    await Launcher.TryOpenAsync("fb-messenger://m.me/dio.923");

    Unfortunately in ios it does'n work.
    I also tried

    await Launcher.TryOpenAsync("fb-messenger-public://m.me/dio.923");

    Did you add url scheme in info.plist ?

  • DimChrisDimChris USMember ✭✭✭✭

    No, could you please give me an example?

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 20

    Add the following url schemes into info.plist

    fb

    fb-messenger

    fb-messenger-public


    Refer to

    https://www.xamarinhelp.com/uri-scheme/

  • DimChrisDimChris USMember ✭✭✭✭
    edited October 20

    Thank you Colex. I add it in info.plist. Now it opens messenger but it doesn't open automatically chat. Is it possible to have different id in android and different id in ios?

    Here is my code
    await Launcher.TryOpenAsync("fb-messenger-public://m.me/dio.chris.923");

  • DimChrisDimChris USMember ✭✭✭✭

    Thank you Colex i will find the way, you helped me a lot!

Sign In or Register to comment.