Facebook App Invites in Android

Posted By : Prince Bhardwaj | 10-Apr-2017

To invite friends to your app, firstley you have to add compiple dependency in app's build.gradle file -

 

dependencies {
   
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    ...
}
 

Note: Make sure to use facebook sdk 4 or later to implement facebook app invites in you app.

Now, to open facebook app invite dialog in your app , use the following code snippet -

 

String appLinkUrl, previewImageUrl;

applicationLinkURL = "YOUR_APP_LINK";
previewImageURL = "YOUR_PREVIEW_IMAGE";

if (AppInviteDialog.canShow()) {
    AppInviteContent content = new AppInviteContent.Builder()
                .setApplinkUrl(applicationLinkURL)
                .setPreviewImageUrl(previewImageURL)
                .build();
    AppInviteDialog.show(this, content);
}
 

applicationLinkURL - App link to what should be opened when recipient clicls on invite.

previewImageURL - Url of image to be used in the invite.

Supporting incoming links to your Application -

When people open yor application through invite, the url  defined in app link will be passed in. Use  AppLinks.getTargetUrlFromInboundIntent from the Bolts framework to obtain this App Link. If your application is not launched from an intent, you can fetch adeffered app link with AppLinkData.withDefferedAppLinkData. An example for this is shown below-


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this);
    Uri targetUrl =
            AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
    if (targetUrl != null) {
        Log.i("ActivityName", "App Link Target URL: " + targetUrl.toString());
    } else {
        AppLinkData.fetchDeferredAppLinkData(
                activity,
                new AppLinkData.CompletionHandler() {
                    @Override
                    public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                        //process applink data
                    }
                });
    }
}
 

THANKS

 

 

About Author

Author Image
Prince Bhardwaj

Prince Bhardwaj is having Talent as Application Developer, he is an enthusiastic team player in Oodles Technologies.

Request for Proposal

Name is required

Comment is required

Sending message..