Search code examples
androidiossharewhatsapp

Sharing App data through WhatsApp (or other messaging service)


I'm trying to figure out if this is possible or not.

Let's say my App can create groups of users. One user creates a new group and other users can then easily enter this group by entering the group number in the same App.

This process relies on the fact that the user who started the group needs to share the group number with the other users and these users must start the App and type over the group number. This is not very user friendly.

It would be better if the App could share the group number with WhatsApp (or other messaging Apps / services) and that on the receiving end the only thing the user has to do is tap on the received group number that would cause my App to be started, so that it would get the group number from WhatsApp.

I know how to share data with WhatsApp, but is it possible to format the (plain text) data in such a way that, when shared with WhatsApp, WhatsApp on the receiving end knows that it has to start my App to share this data with? Preferrably for Andoid and iOS.


Solution

  • What you're looking for is commonly referred to as "deep linking" or "app linking" for mobile apps. This allows a hyperlink to direct a user to a specific, predefined location within the app. Both Android and iOS have native support for this functionality. For Android: You would need to define intent filters in your AndroidManifest.xml to specify that your app can be opened by a particular type of URL.For iOS: You'll need to define URL schemes for your app. You can do this in the Info.plist file

    You would then share this deep link as a regular message via WhatsApp. The receiving user taps the link, and it will open the appropriate app (yours) with the specific context (group number in this case). Both Android and iOS provide ways to extract the data (like the group number) from the deep link when your app is opened. You can then use this data to navigate the user to the appropriate screen or state within your app.

    Here is an example for android:

    <activity android:name=".MainActivity">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/group"/>
    </intent-filter>