developer

Get Started

This section discusses how to get started with the Yahoo Search SDK for Android. You will be building the SDK using Gradle and the Android Manifest, and initializing the SDK with a basic activity.

Build using Gradle

Include yhssdk.aar into your libs folder and add yhssdk and its dependencies to the build.gradle file:

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile(name:'yhssdk-0.4.3', ext:'aar')
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile('com.android.support:support-v4:25.2.0')
    compile 'com.android.support:design:25.2.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

Prepare Android Manifest

Edit your *AndroidManifest.xml* file to add the following permissions:

<!-- Required Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Optional Permissions -->
<!-- To access location and enhance search results -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- To enable contacts search -->
<uses-permission android:name="android.permission.READ_CONTACTS" />

You also must define the following activities (we recommend the Holo.light theme):

<activity android:name="com.yahoo.mobile.client.share.search.ui.activity.SearchActivity"
    android:windowSoftInputMode="adjustPan"
    android:screenOrientation="portrait">
</activity>

Note

  • The Yahoo Search SDK currently only supports portrait mode for SearchActivity.
  • If you want SearchActivity to be launched in a different process, you need to add android:process=”#PROCESS_NAME” in the manifest.
  • Yahoo Search SDK current only supports API 16 and above. If you are planning to target a lower API, make sure you enable hardware acceleration explicitly on Yahoo Search SDK Activities by adding android:hardwareAccelerated=”true” in the manifest

Initialize SDK

Before starting using the SDK, initialize it by passing your app information such as HSPART, HSIMP and APP_ID. Yahoo partner manager will help in setting up those app configurations. We recommend adding this method to your activity OnCreate() method or application class:

import com.yahoo.search.yhssdk.settings.SearchSDKSettings;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initSearchSDK();
    }

    public static void initSearchSDK() {
        SearchSDKSettings.Builder builder = new SearchSDKSettings.Builder(APP_HSPART, APP_HSIMP);
}
}

You can also define optional search settings during initialization. Refer to the Settings section for more details.

To test the search experience, start the SearchActivity: