public static final class

AppInviteInvitation.IntentBuilder

extends Object
java.lang.Object
   ↳ com.google.android.gms.appinvite.AppInviteInvitation.IntentBuilder

Class Overview

Build an Intent to launch the invitation Activity to create and send invitations. The Intent returned from build() should be used to start the Activity using startActivityForResult(android.content.Intent, int).

Example:

     Intent intent = new AppInviteInvitation
         .IntentBuilder("Send Invitations for XYZ app")
         // Ensure valid length for any message used before calling otherwise this will throw
         // an IllegalArgumentException if greater than MAX_MESSAGE_LENGTH.
         .setMessage("Try out XYZ app now")
         .setDeepLink(Uri.parse("http://xyz.com/offer/free_trial_campaign"))
         .setCallToActionText("Find data")
         ...
         .build();
     startActivityForResult(intent, REQUEST_INVITE);
     
 

AppInviteReferral provides accessors to the broadcast parameters from within a custom broadcast receiver.

Summary

Nested Classes
@interface AppInviteInvitation.IntentBuilder.PlatformMode Mode for checking platform types. 
Constants
int MAX_CALL_TO_ACTION_TEXT_LENGTH Maximum length for the invitation button text set in setCallToActionText(CharSequence).
int MAX_EMAIL_HTML_CONTENT Maximum size for the email html content in bytes for setEmailHtmlContent(String).
int MAX_MESSAGE_LENGTH Maximum length for the invitation message set in setMessage(CharSequence).
int MIN_CALL_TO_ACTION_TEXT_LENGTH Minimum length for the invitation button text set in setCallToActionText(CharSequence).
Public Constructors
AppInviteInvitation.IntentBuilder(CharSequence title)
App invite invitation builder.
Public Methods
Intent build()
Builds the Intent to start the invitation Activity.
AppInviteInvitation.IntentBuilder setAccount(Account account)
Sets the name of the account to get a list of people for.
AppInviteInvitation.IntentBuilder setAdditionalReferralParameters(Map<String, String> params)
Adds query parameters to the play store referral URL when the app needs additional referral parameters for other application component referrals.
AppInviteInvitation.IntentBuilder setAndroidMinimumVersionCode(int versionCode)
Sets the minimum version of the android app installed on the receiving device.
AppInviteInvitation.IntentBuilder setCallToActionText(CharSequence callToActionText)
Text shown on the email invitation for the user to accept the invitation.
AppInviteInvitation.IntentBuilder setCustomImage(Uri imageUri)
Sets an image for invitations.
AppInviteInvitation.IntentBuilder setDeepLink(Uri deepLink)
Sets the deep link that is made available to the app when opened from the invitation.
AppInviteInvitation.IntentBuilder setEmailHtmlContent(String htmlContent)
Sets the HTML-formatted (UTF-8 encoded, no JavaScript) content for invites sent through email.
AppInviteInvitation.IntentBuilder setEmailSubject(String subject)
Sets the subject for invites sent by email.
AppInviteInvitation.IntentBuilder setGoogleAnalyticsTrackingId(String trackingId)
Sets the Google Analytics Tracking id.
AppInviteInvitation.IntentBuilder setMessage(CharSequence message)
Sets the invite message that is sent to all invitees.
AppInviteInvitation.IntentBuilder setOtherPlatformsTargetApplication(int targetPlatform, String clientId)
Targets another version of your app to receive the invitation from Android.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MAX_CALL_TO_ACTION_TEXT_LENGTH

Maximum length for the invitation button text set in setCallToActionText(CharSequence).

Constant Value: 20 (0x00000014)

public static final int MAX_EMAIL_HTML_CONTENT

Maximum size for the email html content in bytes for setEmailHtmlContent(String).

Constant Value: 512000 (0x0007d000)

public static final int MAX_MESSAGE_LENGTH

Maximum length for the invitation message set in setMessage(CharSequence).

Constant Value: 100 (0x00000064)

public static final int MIN_CALL_TO_ACTION_TEXT_LENGTH

Minimum length for the invitation button text set in setCallToActionText(CharSequence).

Constant Value: 2 (0x00000002)

Public Constructors

public AppInviteInvitation.IntentBuilder (CharSequence title)

App invite invitation builder.

Parameters
title CharSequence: Sets the title for the invitation Activity.
Returns
Self-reference for method chaining.
Throws
NullPointerException if title is null.

Public Methods

public Intent build ()

Builds the Intent to start the invitation Activity.

Returns
Intent Intent to call with startActivityForResult(Intent, int) to open the App Invite Activity.
Throws
IllegalArgumentException if one of setEmailSubject(String) or setEmailHtmlContent(String) is set while the other is not set. Or if setEmailHtmlContent(String) is set while setCustomImage(Uri) or setCallToActionText(CharSequence) is also set.

public AppInviteInvitation.IntentBuilder setAccount (Account account)

Sets the name of the account to get a list of people for.

Parameters
account Account: Account of one of the accounts on the device user. The account type must be a Google account GOOGLE_ACCOUNT_TYPE.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setAdditionalReferralParameters (Map<String, String> params)

Adds query parameters to the play store referral URL when the app needs additional referral parameters for other application component referrals. These parameters are added to the referral URL sent from the play store and are available to be processed by other application components, for example Google Analytics. The parameters are set as name, value pairs that will be set as query parameter name and value on the referral URL.

Example:

     Map<String, String> referralParams = new HashMap<String, String>();
     referralParams.put("paramOne", "1");
     referralParams.put("paramTwo", "2");

     Intent intent = new AppInviteInvitation
         .IntentBuilder("Send Invitations for XYZ app")
         .setAdditionalReferralParameters(referralParams)
         ...
         .build();
     startActivityForResult(intent, REQUEST_INVITE);
     
 

Parameters
params Map: Referral parameters defined as name value pairs.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setAndroidMinimumVersionCode (int versionCode)

Sets the minimum version of the android app installed on the receiving device. If this minimum version is not installed then the install flow will be triggered.

Parameters
versionCode int: Minimum version of the android app. It will be compared with the android version code and if below this minimum the app will be considered not installed. Defaults to 0 which disables the version check.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setCallToActionText (CharSequence callToActionText)

Text shown on the email invitation for the user to accept the invitation. Default install text used if not set. This must not be set if setEmailHtmlContent(String) is set or build() will throw an Exception.

Parameters
callToActionText CharSequence: Text to use on the invitation button.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.
Throws
IllegalArgumentException if the length is greater than MAX_CALL_TO_ACTION_TEXT_LENGTH or less then MIN_CALL_TO_ACTION_TEXT_LENGTH characters.

public AppInviteInvitation.IntentBuilder setCustomImage (Uri imageUri)

Sets an image for invitations. This must not be set if setEmailHtmlContent(String) is set or build() will throw an Exception.

Parameters
imageUri Uri: the image Uri. The Uri is required to be in absolute format. The Uri can be either a content URI with scheme "android.resource", "content" or "file" or a network url with scheme "http" or "https". The supported image formats are "jpg", "jpeg" and "png".
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setDeepLink (Uri deepLink)

Sets the deep link that is made available to the app when opened from the invitation. This deep link is made available both to a newly installed application and an already installed application. The deep link can be sent to Android and other platforms so should be formatted to support deep links across platforms.

On android, a deep link filter for AppInvite should include an action, category, and data where the data is a uri that matches the deep link. The action must be VIEW and include both category DEFAULT and BROWSABLE as shown in the sample app.

Accessing the deep link in the application after being opened is described in AppInviteReferral.

Parameters
deepLink Uri: The app deep link.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setEmailHtmlContent (String htmlContent)

Sets the HTML-formatted (UTF-8 encoded, no JavaScript) content for invites sent through email. If set, this will be sent instead of the default email. This must be set along with setEmailSubject(String) or build() will throw an Exception. setCustomImage(Uri) and setCallToActionText(CharSequence) must not be set or build() will throw an Exception.

htmlContent must be valid HTML for standard email processing. The pattern %%APPINVITE_LINK_PLACEHOLDER%% should be embedded in your htmlContent and will be replaced with the invitation URL. This url is a link that will launch the app if already installed or take the user to the appropriate app store if not. In both cases the deep link will be available if provided using setDeepLink(Uri). Accessing the deep link in the application after being opened is described in AppInviteReferral.

     Intent intent = new AppInviteInvitation.IntentBuilder("Send Invitations for XYZ app")
         ...
         .setEmailHtmlContent("&lthtml&gt&ltbody&gt"
             + "&lta href=\"%%APPINVITE_LINK_PLACEHOLDER%%\"&gtXYZ Free Trial&lt/a&gt"
             + "&lt/body&gt&lt/html&gt")
         .setEmailSubject("XYZ Offer")
         ...
         .build();
     
 
Must be valid (MAX_EMAIL_HTML_CONTENT bytes or less).

Parameters
htmlContent String: The html-formatted content for the email.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.
Throws
IllegalArgumentException if the content size is greater than MAX_EMAIL_HTML_CONTENT bytes.

public AppInviteInvitation.IntentBuilder setEmailSubject (String subject)

Sets the subject for invites sent by email. This must be set along with setEmailHtmlContent(String) or build() will throw an Exception.

Parameters
subject String: The subject for the email.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setGoogleAnalyticsTrackingId (String trackingId)

Sets the Google Analytics Tracking id. The tracking id should be created for the calling application under Google Analytics. See more about how to get a tracking id . The tracking id is recommended so that invitations sent from the calling application are available in Google Analytics.

Parameters
trackingId String: String of the form UA-xxxx-y
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.

public AppInviteInvitation.IntentBuilder setMessage (CharSequence message)

Sets the invite message that is sent to all invitees. Must be valid (MAX_MESSAGE_LENGTH bytes or less), including the length of translated and generated messages. The message can be edited by the sender.

Parameters
message CharSequence: The invite message.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.
Throws
IllegalArgumentException if the length is greater than MAX_MESSAGE_LENGTH.

public AppInviteInvitation.IntentBuilder setOtherPlatformsTargetApplication (int targetPlatform, String clientId)

Targets another version of your app to receive the invitation from Android. This is needed only when there are multiple client IDs defined in your Google Developer Console project. Setting the target client ID for the invitation ensures that it goes to the correct app.

Parameters
targetPlatform int: Platform for the clientId. Must be PROJECT_PLATFORM_IOS or PROJECT_PLATFORM_ANDROID.
clientId String: Google generated client Id from the Developer console.
Returns
AppInviteInvitation.IntentBuilder Self-reference for method chaining.
Throws
IllegalArgumentException if is not PROJECT_PLATFORM_IOS or PROJECT_PLATFORM_ANDROID.