Skip to content

Send Your First Smart Invite on Android

Prerequisite

Send Smart Invites

GetSocial SDK provides two ways to send Smart Invites: using our data API or via provided GetSocial UI.

Smart Invites are powered by Smart Links. Internally we generate a unique Smart Link for each invitation and attach information about the sender to the Smart Link.

You can attach string-string key-value pairs to pass custom data with a Smart Link. Also, you can add one of the predefined parameters to change the behaviour of the Smart Link.

Receiving user can get the data attached to the Smart Link on the app start, even if an app was just installed from the store.

To create LinkParams object with key-value pairs you want to attach to the Smart Link:

```java tab=”Java”
LinkParams linkParams = new LinkParams();
linkParams.put(“custom_key”, “custom_value”); // custom key
linkParams.put(“$title”, “Custom landing page title”); // predefined key

```kotlin tab="Kotlin"
val linkParams = LinkParams()
linkParams["custom_key"] = "custom_value" // custom key
linkParams["\$title"] = "Custom landing page title" // predefined key

Supported value types

The LinkParams object supports String values for custom data, other types will be ignored.

Customize Invite Message Content

Some invite channels allow to customize text, image and subject. Check the details here.

Default Smart Invites message can be defined on the GetSocial DashboardAcquisition section → Smart Invites tab.

To customize content on the client side:

```java tab=”Java”
InviteContent inviteContent = InviteContent.createBuilder()
.withText(“I can’t stop playing! Get it here [APP_INVITE_URL]”) // NOTE: if you customize the text [APP_INVITE_URL] placeholder have to be used
.withSubject(“Check out this app”)
.withMediaAttachment(MediaAttachment.imageUrl(“https://docs.getsocial.im/images/logo.png”))
.build();

```kotlin tab="Kotlin"
val inviteContent = InviteContent.createBuilder()
    .withText("I can't stop playing! Get it here [APP_INVITE_URL]") // NOTE: if you customize the text [APP_INVITE_URL] placeholder have to be used
    .withSubject("Check out this app")
    .withMediaAttachment(MediaAttachment.imageUrl("https://docs.getsocial.im/images/logo.png"))
    .build()

Send Invites Using GetSocial Data API

The code below shows how to send Smart Invite with custom data and custom content attached via a Facebook channel. All supported Invite Channels are listed in InviteChannelIds class.

```java tab=”Java”
String inviteChannelId = InviteChannelIds.FACEBOOK;

// Check if invite channel is available on the device.
// Alternatively you can get all available channels via GetSocial.getInviteChannels()
if(GetSocial.isInviteChannelAvailable(inviteChannelId)) {
GetSocial.sendInvite(inviteChannelId, inviteContent, linkParams, new InviteCallback() {
@Override
public void onComplete() {
Log.i(“GetSocial”, “Invitation with referral data via FACEBOOK was sent”);
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    @Override
    public void onCancel() {
        Log.i("GetSocial", "Invitation with referral data via FACEBOOK was cancelled");
    }

    @Override
    public void onError(Throwable throwable) {
        Log.e("GetSocial", "Invitation with referral data via FACEBOOK failed, error: " + throwable.getMessage());
    }
});

}
kotlin tab=”Kotlin”
val inviteChannelId = InviteChannelIds.FACEBOOK

// Check if invite channel is available on the device.
// Alternatively you can get all available channels via GetSocial.getInviteChannels()
if (GetSocial.isInviteChannelAvailable(inviteChannelId)) {
GetSocial.sendInvite(inviteChannelId, inviteContent, linkParams, object : InviteCallback{
override fun onComplete() {
println(“Invitation with referral data via FACEBOOK was sent”)
}

override fun onCancel() {
println(“Invitation with referral data via FACEBOOK was cancelled”)
}

override fun onError(throwable: Throwable) {
println(“Invitation with referral data via FACEBOOK failed, error: ${throwable.message}”)
}
})
}
```

Facebook Share Dialog will be presented as a result:

GetSocial Smart Ivites View

Send Invites Using GetSocial Smart Invites View

GetSocial UI library provides a view that lists all Smart Invite channels available on the device and enabled on the GetSocial Dashboard.

To send an invite with custom data attached using GetSocial UI create and show the view:

```java tab=”Java”
boolean wasShown = GetSocialUi.createInvitesView()
.setLinkParams(linkParams)
.setCustomInviteContent(inviteContent)
.setInviteCallback(new InviteUiCallback() {
@Override
public void onComplete(String channelId) {
Log.i(“GetSocial”, “Invitation was sent”);
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
        @Override
        public void onCancel(String channelId) {
            Log.i("GetSocial", "Invite cancelled");
        }

        @Override
        public void onError(String channelId, Throwable throwable) {
            Log.e("GetSocial", "Invite failed: " + throwable.getMessage());
        }
    })
    .show();

Log.i(“GetSocial”, “GetSocial Smart Invites UI was shown: ” + wasShown);

```kotlin tab="Kotlin"
val wasShown = GetSocialUi.createInvitesView()
    .setLinkParams(linkParams)
    .setInviteCallback(object: InviteUiCallback {
        override fun onComplete(channelId : String) {
            println("Invitation was sent")
        }

        override fun onCancel(channelId : String) {
            println("Invite cancelled")
        }

        override fun onError(channelId : String, throwable: Throwable) {
            println("Invite failed: ${throwable.message}")
        }
    })
    .show()
println("GetSocial Smart Invites UI was shown: ${wasShown}")

You will see the following view on your screen:

GetSocial Smart Ivites View

GetSocial.sendInvite() and GetSocialUi.createInvitesView() are opening the selected invite channel with pre-filled invite message. If you want to handle sharing on your own and just need a Smart Link to invite uses you can use the following API:

```java tab=”Java”
LinkParams linkParams = new LinkParams();
linkParams.put(“$channel”, “my_custom_channel”); // optional: set sharing channel for analytics, by default channel is set to “manual”

GetSocial.createInviteLink(linkParams, new Callback() {
@Override
public void onSuccess(String smartLink) {
_log.logInfoAndToast(“Invite link: ” + smartLink);
}

```kotlin tab="Kotlin"
val linkParams = LinkParams()
linkParams["\$channel"] = "my_custom_channel" // optional: set sharing channel for analytics, by default channel is set to "manual"

GetSocial.createInviteLink(linkParams, object : Callback<String> {
    override fun onSuccess(smartLink: String) {
        println("Invite link: ${smartLink}")
    }

    override fun onFailure(exception: GetSocialException) {
        println("Failed to create invite link, error: ${exception.message}")
    }
})

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁