Mobile SDKs: Integrate Bazaarvoice into your native Android and iOS apps.
Content Display
The Bazaarvoice Mobile SDKs provide access to most of the core products Bazaarvoice offers. To learn more, go to the Mobile SDK documentation home page.
Contents
This documentation explains how consumer-generated content (CGC) can be displayed using the mobile SDK either by loading the Infinite Recycle View or by accessing the data directly via the API.
Introduction
Use the Curations module of the Bazaarvoice Mobile SDKs to harness a wealth of social media content tailored for your marketing needs, and display it where it can deliver engagement, trust, and conversion: your Android app.
Depending on your application requirements, there are two ways to fetch your Curations data for display:
- CurationsInfiniteRecyclerView (recommended) - Use our custom, sub-classed RecyclerView to handle the entire display, scrolling, and paging.
- API Direct - If you have UI customization that don't fit a RecyclerView, you can call the API directly to fetch the Curations feed items you need for display.
An example code walk-through can be found in com.bazaarvoice.bvsdkdemoandroid.curations.DemoCurationsPostActivity
. For a more comprehensive demonstration of the Conversations API, please also see com.bazaarvoice.bvsdkdemoandroid.detail.DemoFancyProductDetailActivity
Installation instructions
Click here to see how to install and configure the BVSDK.
Installation with Gradle
Include the Maven Central repository and add the appropriate Bazaarvoice Mobile SDK modules to your dependencies:
dependencies { implementation 'com.bazaarvoice.bvandroidsdk:curations:{BV_SDK_VERSION}.+' // Provides API Direct implementation 'com.bazaarvoice.bvandroidsdk:curations-ui:{BV_SDK_VERSION}.+' // Provides View that Handles API Direct + Analytics for you implementation 'com.google.android.gms:play-services-ads:9.{YOUR_PLAY_SERVICES_VERSION}' implementation 'com.android.support:recyclerview-v7:25.{YOUR_SUPPORT_LIBRARY_VERSION}' } repositories { mavenCentral() }
Replace the {tokens}
, including brackets, with the appropriate values. Refer to the Installation guide for {BV_SDK_VERSION}
.
Extending the application
Create a class that extends android.app.Application
, and initialize the Mobile SDK using its builder.
You can find a full list of build options in BVSDK.java
.
public class MyApplication extends Application { @Override public void onCreate(){ super.onCreate(); BVSDK.builder(application, BazaarEnvironment.PRODUCTION) .logLevel(BVLogLevel.VERBOSE) // Optional: Set the log level. Default level is ERROR. .dryRunAnalytics(false) // Optional: Set analytics to log only, not make a network request. Default is false. .okHttpClient(okHttpClient) // Optional: Use you own okHttpClient instance .build(); } }
App manifest file
Add the following to your AndroidManifest.xml
file.
<!-- set the name of the class for the application entry --> <application android:name=".MyApplication"> </application>
Curations infinite recycler view
The BVSDK comes with CurationsInfiniteRecyclerView
class, which you can simply drop into your xml layout, and define the desired attributes there. The View will manage creation of its own adapter, the layout of each cell (including the proper badges for the social channel), fetching of Curations Feed Items, paging to give it an infinite scroll, as well as sending off all of the required analytic events.
Creating the image loader class
First you should provide an image loader class which should implement the com.bazaarvoice.bvandroidsdk.CurationsImageLoader
interface. This is done to ensure optimal image loading for a large grid of images, while allowing you to tie this into your own image loading solution so that we do not enforce this View to use any specific library. An example implementation with Picasso is visible in the com.bazaarvoice.bvsdkdemoandroid.curations.DemoImageLoader
class. This implements tagging of the ImageView
when creating the request in order to implement cancelling of network requests which could prevent a long request queue from forming, and delaying the display of images.
Adding the view
Add the view to your layout file:
<com.bazaarvoice.bvandroidsdk.CurationsInfiniteRecyclerView android:id="@+id/my_curations_view" android:layout_width="match_parent" android:layout_height="@dimen/my_row_height" app:curationSpanCount="1" app:curationReverseLayout="false" app:curationCellWidthRatio="1" app:curationCellHeightRatio="1" app:curationPageSize="50" app:curationOrientation="horizontal"/>
Start loading in activity
Then in your Activity#onCreate()
, get the View:
CurationsInfiniteRecyclerView myCurationsView = (CurationsInfiniteRecyclerView) findViewById(R.id.my_curations_view);
Create a CurationsFeedRequest
with your desired parameters (the view will handle the paging):
final CurationsFeedRequest request = new CurationsFeedRequest .Builder(Arrays.asList("feed1", "feed2")) .build();
Enable the view to start loading, by passing it the required parameters, and then calling load. This can be implemented with the following fluent API:
myCurationsView .setRequest(request) .setImageLoader(curationsImageLoader) .setOnPageLoadListener(new CurationsInfiniteRecyclerView.OnPageLoadListener() { @Override public void onPageLoadSuccess(int pageIndex, int pageSize) { // onSuccess, could cancel a spinner here when pageIndex == 0 // pageSize will alway be <= the provided page size in xml } @Override public void onPageLoadFailure(int pageIndex, Throwable throwable) { // onFailure, could cancel a spinner here when pageIndex == 0 // throwable contains the reason for a page load failure } }) .setOnFeedItemClickListener(new CurationsInfiniteRecyclerView.OnFeedItemClickListener() { @Override public void onClick(CurationsFeedItem curationsFeedItem) { MyActivity activity = MyActivity.this; if (!activity.isFinishing()) { String productId = curationsFeedItem.getProductId(); String feedItemId = String.valueOf(curationsFeedItem); MyRouter.transitionToCurationsFeedItem(activity, productId, feedItemId); } } }) .load();
API direct
To request a list of Curations Feed Items programatically simply create a request object with the com.bazaarvoice.bvandroidsdk.CurationsFeedRequest.Builder
class, a callback object with the com.bazaarvoice.bvandroidsdk.CurationsFeedCallback
class, and provide them to an instance of the com.bazaarvoice.bvandroidsdk.BVCurations
class:
// For a full list of options, check out the Builder class final List myGroups = Arrays.asList("__group1__", "__group2"); final List myTags = Arrays.asList("tag1", "tag2"); final CurationsFeedRequest request = new CurationsFeedRequest .Builder(myGroups) .withProductData(true) .tags(myTags) .location(latitude, longitude) .build(); // This callback will be weakly held, so make sure that you retain it for as // long as you would like final CurationsFeedCallback callback = new CurationsFeedCallback() { @Override public void onSuccess(List feedItems) { // List of feed items loaded from the request } @Override public void onFailure(Throwable throwable) { // Throwable describing failure to fetch feed items } } // It is best to instantiate the BVCurations object once and reuse it as a // singleton bvCurations.getCurationsFeedItems(request, callback);