Builder

class Builder
kotlin.Any
   ↳ androidx.recommendation.app.ContentRecommendation.Builder

Builder class for ContentRecommendation objects. Provides a convenient way to set the various fields of a ContentRecommendation.

Example:

ContentRecommendation rec = new ContentRecommendation.Builder()
              .setIdInfo(id, "MyTagId")
              .setTitle("My Content Recommendation")
              .setText("An example of content recommendation")
              .setContentImage(myBitmap)
              .setBadgeIcon(R.drawable.app_icon)
              .setGroup("Trending")
              .build();
      

Summary

Public constructors

Constructs a new Builder.

Public methods

ContentRecommendation!

Combine all of the options that have been set and return a new ContentRecommendation object.

ContentRecommendation.Builder!
setAutoDismiss(autoDismiss: Boolean)

Sets the flag indicating if the recommendation should be dismissed automatically.

ContentRecommendation.Builder!
setBackgroundImageUri(@Nullable imageUri: String?)

Sets the Content URI that will be used to retrieve the background image for the recommendation.

ContentRecommendation.Builder!
setBadgeIcon(@DrawableRes iconResourceId: Int)

Sets the resource ID for the recommendation badging icon.

ContentRecommendation.Builder!
setColor(color: Int)

Sets the accent color value to be used in the UI when displaying this content recommendation to the user.

ContentRecommendation.Builder!

Sets the recommendation image.

ContentRecommendation.Builder!
setContentIntentData(intentType: Int, intent: Intent!, requestCode: Int, @Nullable options: Bundle?)

Sets the data for the Intent that will be issued when the user clicks on the recommendation.

ContentRecommendation.Builder!

Sets the content types associated with the content recommendation.

ContentRecommendation.Builder!
setDismissIntentData(intentType: Int, @Nullable intent: Intent?, requestCode: Int, @Nullable options: Bundle?)

Sets the data for the Intent that will be issued when the recommendation gets dismissed from the Home Screen, due to an user action.

ContentRecommendation.Builder!
setGenres(genres: Array<String!>!)

Sets the content genres for the recommendation.

ContentRecommendation.Builder!
setGroup(@Nullable groupTag: String?)

Sets the String group ID tag for the recommendation.

ContentRecommendation.Builder!
setIdTag(idTag: String!)

Sets the Id tag that uniquely identifies this recommendation object.

ContentRecommendation.Builder!
setMaturityRating(maturityRating: String!)

Sets the maturity level rating for the content.

ContentRecommendation.Builder!
setPricingInformation(priceType: String!, @Nullable priceValue: String?)

Sets the pricing and availability information for the recommendation.

ContentRecommendation.Builder!
setProgress(max: Int, progress: Int)

Sets the progress information for the content pointed to by the recommendation.

ContentRecommendation.Builder!

Sets the running time (when applicable) for the content.

ContentRecommendation.Builder!
setSortKey(@Nullable sortKey: String?)

Sets the String sort key for the recommendation.

ContentRecommendation.Builder!
setSourceName(@Nullable source: String?)

Sets the source application name for the recommendation.

ContentRecommendation.Builder!
setStatus(contentStatus: Int)

Sets the availability status for the content.

ContentRecommendation.Builder!
setText(@Nullable description: String?)

Sets the description text for the recommendation.

ContentRecommendation.Builder!
setTitle(title: String!)

Sets the content title for the recommendation.

Public constructors

<init>

Builder()

Constructs a new Builder.

Public methods

build

fun build(): ContentRecommendation!

Combine all of the options that have been set and return a new ContentRecommendation object.

setAutoDismiss

fun setAutoDismiss(autoDismiss: Boolean): ContentRecommendation.Builder!

Sets the flag indicating if the recommendation should be dismissed automatically.

Auto-dismiss notifications are automatically removed from the Home Screen when the user clicks on them.

Parameters
autoDismiss Boolean: A boolean indicating if the recommendation should be auto dismissed or not.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setBackgroundImageUri

fun setBackgroundImageUri(@Nullable imageUri: String?): ContentRecommendation.Builder!

Sets the Content URI that will be used to retrieve the background image for the recommendation.

Parameters
imageUri String?: A Content URI pointing to the recommendation background image.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setBadgeIcon

fun setBadgeIcon(@DrawableRes iconResourceId: Int): ContentRecommendation.Builder!

Sets the resource ID for the recommendation badging icon.

The resource id represents the icon resource in the source application package. If not set, or an invalid resource ID is specified, the application icon retrieved from its package will be used by default.

Parameters
iconResourceId Int: An integer id for the badge icon resource.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setColor

fun setColor(color: Int): ContentRecommendation.Builder!

Sets the accent color value to be used in the UI when displaying this content recommendation to the user.

Parameters
color Int: An integer value representing the accent color for this recommendation.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setContentImage

fun setContentImage(image: Bitmap!): ContentRecommendation.Builder!

Sets the recommendation image.

Parameters
image Bitmap!: A Bitmap containing the recommendation image.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setContentIntentData

fun setContentIntentData(intentType: Int, intent: Intent!, requestCode: Int, @Nullable options: Bundle?): ContentRecommendation.Builder!

Sets the data for the Intent that will be issued when the user clicks on the recommendation.

The Intent data fields provided correspond to the fields passed into the PendingIntent factory methods, when creating a new PendingIntent. The actual PengindIntent object will only be created at the time a recommendation is posted to the Home Screen.

Parameters
intentType Int: The type of PendingIntent to be created when posting this recommendation.
intent Int: The Intent which to be issued when the recommendation is clicked on.
requestCode Int: The private request code to be used when creating the PendingIntent
options Int: Only used for the Activity Intent type. Additional options for how the Activity should be started. May be null if there are no options.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setContentTypes

fun setContentTypes(types: Array<String!>!): ContentRecommendation.Builder!

Sets the content types associated with the content recommendation. The first tag entry will be considered the primary type for the content and will be used for ranking purposes. Other secondary type tags may be provided, if applicable, and may be used for filtering purposes.

Parameters
types Array<String!>!: Array of predefined type tags (see the CONTENT_TYPE_* constants) that describe the recommended content.

setDismissIntentData

fun setDismissIntentData(intentType: Int, @Nullable intent: Intent?, requestCode: Int, @Nullable options: Bundle?): ContentRecommendation.Builder!

Sets the data for the Intent that will be issued when the recommendation gets dismissed from the Home Screen, due to an user action.

The Intent data fields provided correspond to the fields passed into the PendingIntent factory methods, when creating a new PendingIntent. The actual PengindIntent object will only be created at the time a recommendation is posted to the Home Screen.

Parameters
intentType Int: The type of PendingIntent to be created when posting this recommendation.
intent Int: The Intent which gets issued when the recommendation is dismissed from the Home Screen.
requestCode Int: The private request code to be used when creating the PendingIntent
options Int: Only used for the Activity Intent type. Additional options for how the Activity should be started. May be null if there are no options.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setGenres

fun setGenres(genres: Array<String!>!): ContentRecommendation.Builder!

Sets the content genres for the recommendation. These genres may be used for content ranking. Genres are open ended String tags.

Some examples: "comedy", "action", "dance", "electronica", "racing", etc.

Parameters
genres Array<String!>!: Array of genre string tags that describe the recommended content.

setGroup

fun setGroup(@Nullable groupTag: String?): ContentRecommendation.Builder!

Sets the String group ID tag for the recommendation.

Recommendations in the same group are ranked by the Home Screen together, and the sort order within a group is respected. This can be useful if the application has different sources for recommendations, like "trending", "subscriptions", and "new music" categories for YouTube, where the user can be more interested in recommendations from one group than another.

Parameters
groupTag String?: A String containing the group ID tag for this recommendation.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setIdTag

fun setIdTag(idTag: String!): ContentRecommendation.Builder!

Sets the Id tag that uniquely identifies this recommendation object.

Parameters
idTag String!: A String tag identifier for this recommendation.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setMaturityRating

fun setMaturityRating(maturityRating: String!): ContentRecommendation.Builder!

Sets the maturity level rating for the content.

Parameters
maturityRating String!: A tag indicating the maturity level rating for the content. This tag must be one of the predefined maturity rating tags (see the CONTENT_MATURITY_* constants).

setPricingInformation

fun setPricingInformation(priceType: String!, @Nullable priceValue: String?): ContentRecommendation.Builder!

Sets the pricing and availability information for the recommendation. The provided information will indicate the access model for the content (free, rental, purchase or subscription) and the price value (if not free).

Parameters
priceType String!: Pricing type for this content. Must be one of the predefined pricing type tags (see the CONTENT_PRICING_* constants).
priceValue String!: A string containing a representation of the content price in the current locale and currency.

setProgress

fun setProgress(max: Int, progress: Int): ContentRecommendation.Builder!

Sets the progress information for the content pointed to by the recommendation.

Parameters
max Int: The maximum value for the progress of this content.
progress Int: The progress amount for this content. Must be in the range (0 - max).
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setRunningTime

fun setRunningTime(length: Long): ContentRecommendation.Builder!

Sets the running time (when applicable) for the content.

Parameters
length Long: The running time, in seconds, of the content.

setSortKey

fun setSortKey(@Nullable sortKey: String?): ContentRecommendation.Builder!

Sets the String sort key for the recommendation.

The sort key must be a String representation of a float number between 0.0 and 1.0, and is used to indicate the relative importance (and sort order) of a single recommendation within its specified group. The recommendations will be ordered in decreasing order of importance within a given group.

Parameters
sortKey String?: A String containing the sort key for this recommendation.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setSourceName

fun setSourceName(@Nullable source: String?): ContentRecommendation.Builder!

Sets the source application name for the recommendation.

If the source name is never set, or set to null, the application name retrieved from its package will be used by default.

Parameters
source String?: A String containing the recommendation source name.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setStatus

fun setStatus(contentStatus: Int): ContentRecommendation.Builder!

Sets the availability status for the content. This status indicates whether the referred content is ready to be consumed on the device, or if the user must first purchase, rent, subscribe to, or download the content.

Parameters
contentStatus Int: The status value for this content. Must be one of the predefined content status values (see the CONTENT_STATUS_* constants).

setText

fun setText(@Nullable description: String?): ContentRecommendation.Builder!

Sets the description text for the recommendation.

Parameters
description String?: A String containing the recommendation description text.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.

setTitle

fun setTitle(title: String!): ContentRecommendation.Builder!

Sets the content title for the recommendation.

Parameters
title String!: A String containing the recommendation content title.
Return
ContentRecommendation.Builder!: The Builder object, for chaining.