Add Features¶
The following sections discuss the various features that you can add to your app with the Android SDK:
Integrate Search-to-Link¶
About Search-to-Link¶
The Search SDK by default allows your app’s users to search, select, and share Web links, images and videos. The App has to implement the interfaces as below to get the metadata from the search results which was clicked by the user.
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
builder.setSearchResultClickListener(this);
Intent intent = builder.buildIntent(context);
yourActivity.startActivityForResult(intent, REQUEST_CODE_SEARCH_TO_LINK);
- The Search SDK provides default Web vertical “preview” activity for the user to preview the web link before sharing it. Preview is enabled by default. If you want to disable previews, call the corresponding API:
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
...
// disabling preview on Web
builder.enableWebPreview(false);
Note
Only single selection mode is supported. Once the user taps on an item (Web URL, image, or video), the activity will return the selected data.
Handle Data¶
This is sample code to handle share data that comes from any of the verticals:
- Web vertical callback
@Override
public void onWebResultClicked(WebSearchResult webData) {
Log.d(TAG, "Web search share data:" + webData.getUrl());
}
- Image vertical callback
@Override
public void onImageResultClicked(ImageSearchResult imageData) {
Log.d(TAG, "Image share photo url:" + imageData.getPhotoUrl());
Log.d(TAG, "Image share thumbnail url:" + imageData.getThumbUrl());
Log.d(TAG, "Image share title:" + imageData.getTitle());
}
- Video vertical callback
@Override
public void onVideoResultClicked(VideoSearchResult videoData) {
Log.d(TAG, "Video Search share data:" + videoData.getUrl());
}
We currently support three types of data that the user can share: Web, Images, Video.
The WebSearchResult has the following structure:
@Override
public void onWebResultClicked(WebSearchResult webData) {
// Title of the Web link to be shared. This can be empty.
String title = webData.getTitle();
// Source Web page URL.
String source_url = webData.getUrl();
}
The ImageSearchResult has the following structure:
@Override
public void onImageResultClicked(ImageSearchResult imageData) {
// The photo url
String photoUrl = imageData.getPhotoUrl();
// The thumbnail url
String thumbUrl = imageData.getThumbUrl();
// The title
String title = imageData.getTitle();
}
The VideoSearchResult has the following structure:
@Override
public void onVideoResultClicked(VideoSearchResult videoData) {
// The video url
String videoUrl = videoData.getUrl());
// The duration of the video
String duration = videoData.getDuration();
// Age of the video
String age = videoData.getAge());
// Title
String title = videoData.getTitle());
}
Integrate In-App Search¶
The Yahoo Search SDK provides an activity that handles the whole search UI experience. Start the activity with the following code:
SearchActivity.IntentBuilder intentBuilder = new SearchActivity.IntentBuilder();
Intent i = intentBuilder.buildIntent(this);
startActivity(i);
You can also provide a predefined query. Search results will be shown as soon as the activity starts. Simply call the corresponding method on the builder:
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
builder.setQueryString("yahoo");
Intent i = builder.buildIntent(context);
startActivity(i);
By default Web, Image and Video tabs are shown but that can disabled as below:
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
//To diable image vertical
builder.enableImageSearch(false);
//To diable video vertical
builder.enableVideoSearch(false);
Intent i = builder.buildIntent(context);
startActivity(i);
Note
- The Web vertical cannot be disabled.
If you only want to show search suggestions (not search results), the Search SDK
provides the “Search Suggest” launch state in which the query is prefilled on the
SearchBar
and search suggestions are shown accordingly. Simply call the launchSuggestions
method.
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
builder.setQueryString(query);
builder.launchWithSuggestions(true);
Intent i = builder.buildIntent(context);
startActivity(i);
Show App and Contact Suggestions¶
In addition to keyword search suggestions, you can enable local suggestions for apps and contacts on your phone.
To enable apps suggestions, call the showAppSuggestions
method:
builder.showAppSuggestions(true);
To enable apps suggestions, call the showContactSuggestions
method:
builder.showContactSuggestions(true);
Show Trending Search Suggestions¶
SearchActivity
shows trending sugggestions when the query field is empty or
when the user clears the searchbar text. These suggestions are similar to the
ones shown on the Yahoo home page.
The trending search suggestion will be shown if the APP_ID is set using SearchSDKSettings.Builder
.
SearchSDKSettings.Builder builder = new SearchSDKSettings.Builder(APP_HSPART, APP_HSIMP);
builder.setAppId(APP_ID);
Type tag for YHS experimentation¶
Developers can perform experiments, or segment traffic and revenue between different entry points within their apps. If specified, the TYPE_TAG attribute will associate corresponding search traffic and revenue with the desired label, which can then be accessed by Yahoo Partner Managers.
SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder();
builder.setTypeTag("TYPE_TAG");
Intent i = builder.buildIntent(context);
startActivity(i);
Show Search History¶
In addition to trending suggestions, users will see the search history when the query field is empty. Search history is enabled by default.
To change the number of search history items to be shown,
call the setNumberOfHistoryItems
method:
builder.setNumberOfHistoryItems(5);
Note
The number of history items should be greater or equals than 0. An
IllegalArgumentException
will be thrown otherwise. “Show All History” option
is available below set number of history items. On tap of this label you can see
maximum of hundred history items.
Integrate native ads¶
The Search SDK can display Gemini native ads within the Image vertical search interface. To enable proper revenue attribution, set your Flurry API key using setupFlurryAds
.
For more information on registering with Flurry to enable Gemini ads, refer to the Get Started section to create your API key.
You will also need to create an ad space and define your ad space name which will be passed in the API as below.
SearchSDKSettings.Builder builder = new SearchSDKSettings.Builder(#YOUR_DEV_APPID);
builder.setupFlurryAds(#YOUR_FLURRY_API_KEY, #YOUR_AD_SPACE_NAME);