Developer Console

Direct linking

The API allows you to direct customers to a specific product page, a search results page or the Amazon home page via Linkservice. You specify the type of page you want to open, and the LinkService takes care of the formation of a URL with your associate tag and opening the link in a browser.

Prerequisite

The LinkService is available on all Android devices running 1.6 and higher. Apps using the LinkService can be distributed through any Android app store as long as the same app is offered through Amazon.

Customer Experience

Direct Linking enables you to provide the following experiences:

  • Direct customers to Amazon product page
  • Direct customers to Amazon search result page
  • Direct customers to Amazon home page

Direct to Amazon Product Page

You can specify a product ID in the Product Page Request and using the LinkService direct customers to the mobile optimized Amazon product page. Customers can find product details, read reviews, discover related products and complete purchase after signing in to their Amazon account.

Important Note: LinkService does not provide the capability to retrieve product information or fetch product ads. Presenting the product offer in you app is specific to your implementation. 

See how you can find product ID (also called ASIN) on Amazon retail website [here][mobile-associates/mas-finding-product-id].

Direct to Amazon Search Page

You can specify search term and keyword and using the LinkService, direct customers to mobile optimized Amazon search result page. Customers can browse through the search result, select products, and complete the purchase after signing in to their Amazon account.

See available product categories and compatible sorting and filtering options here.

Direct to Amazon Home Page

You also have the option to direct customers directly to mobile optimized Amazon home page where they can search, discover and purchase products of their choice.

For overriding Amazon links in a WebView client, you should place the LinkService.overrideLinkInvocation() API in the shouldOverrideUrlLoading() method of a WebView client.

webView = (WebView)findViewById(R.id.webview);
webView.setWebViewClient(new MAAWebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String sampleHTML = "<html><head></head><body><a href=\"http://www.amazon.com/gp/product/B008GGCAVM\">Kindle</a></body></html>";
webView.loadData(sampleHTML, "text/html", null);

private class MAAWebViewClient extends WebViewClient {
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		try {
			LinkService linkService = AssociatesAPI.getLinkService();
			return linkService.overrideLinkInvocation(view, url);
		} catch (NotInitializedException e) {
			Log.v(TAG, e.printStackTrace());
		}
		return false;
	}
}									

Required APIs

To implement Direct Linking to Amazon, you need to use the following classes:

  • AssociatesAPI - used to initialize the API
  • LinkService - used to initiate API requests

You will use the following to create link requests:

  • OpenHomePageRequest() - used to create request to open Amazon.com home page
  • OpenProductPageRequest() - used to create request to open a specific product detail page on Amazon.com
  • OpenSearchPageRequest() - used to create request to open a search results page by specifying keyword and category

The rest of the document will walk your through the implementation details for Direct Linking to Amazon.

Update the Android Manifest

Making requests to the Amazon Mobile Associates API requires the INTERNET permission. The ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions are optional. These permissions need to be declared outside of the tags in your `AndroidManifest.xml` file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Initialize the API

In your Activity.onCreate(), initialize the API by calling AssociatesAPI.initialize(config). Calling any other API method before initialization will cause a NotInitializedException.

  protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  AssociatesAPI.initialize(new AssociatesAPI.Config(APPLICATION_KEY, this));
}

You will need the Application Key to initialize the API. To get the Application Key, log on to Amazon Apps & Games Developer Portal, click on the "My Apps" tab and then select an existing app or click on the "Add a New App" button. When creating a new app, just fill in the "App Title" and "Form Factor" fields and click the "Save" button. The next screen will show the unique Application Key value, which is a 32-character globally unique alphanumeric string that is used to identify your app. The same Application Key can be used across platforms, but each distinct app must have a unique Application Key. 

Direct to Amazon Home Page

To direct customers to Amazon's home page, construct an OpenHomePageRequest and pass it to the LinkService.openRetailPage() method.

openHomePageButton = (Button)findViewById(R.id.open_home_page_button);
openHomePageButton.setEnabled(true);
openHomePageButton.setOnClickListener(new View.OnClickListener() {

  public void onClick(View view) {
    OpenHomePageRequest request = new OpenHomePageRequest();
    try {
        LinkService linkService = AssociatesAPI.getLinkService();
        linkService.openRetailPage(request);
    } catch (NotInitializedException e) {
        Log.v(TAG, e.printStackTrace());
    }
  }
});

Direct to Amazon Product Detail Page

To direct customers to Amazon product detail page, construct an OpenProductPageRequest by specifying the product ID, also called ASIN, and pass the page request to the LinkService.openRetailPage() method.

String asin = "B008GGCAVM";
openProductPageButton = (Button)findViewById(R.id.open_product_page_button);
	openProductPageButton.setEnabled(true);
	openProductPageButton.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
	OpenProductPageRequest request = new OpenProductPageRequest(asin);
		try {
			LinkService linkService = AssociatesAPI.getLinkService();
			linkService.openRetailPage(request);
		} catch (NotInitializedException e) {
			Log.v(TAG, e.printStackTrace());
		}
	}
});

For information about how to find the ASIN for a product, see Finding Product ID.

Direct to Amazon Search Result Page

To direct customers to Amazon product search result page, construct an OpenSearchPageRequest by specifying the search keyword and pass the search request to the LinkService.openRetailPage() method.

String searchTerm = "kindle";
openSearchPageButton = (Button)findViewById(R.id.open_search_page_by_term_button);
openSearchPageButton.setEnabled(true);
openSearchPageButton.setOnClickListener(new View.OnClickListener() {

	public void onClick(View view) {
		OpenSearchPageRequest request = new OpenSearchPageRequest(searchTerm);
		try {
			LinkService linkService = AssociatesAPI.getLinkService();
			linkService.openRetailPage(request);
		} catch (NotInitializedException e) {
			Log.v(TAG, e.printStackTrace());
		}
	}
});

In the OpenSearchPageRequest, you can also specify product category.

String searchTerm = "kindle";
String category = "Electronics";
openSearchPageButton = (Button)findViewById(R.id.open_search_page_by_term_button);
openSearchPageButton.setEnabled(true);
openSearchPageButton.setOnClickListener(new View.OnClickListener() {

	public void onClick(View view) {
		OpenSearchPageRequest request = new OpenSearchPageRequest(category, searchTerm);
		try {
			LinkService linkService = AssociatesAPI.getLinkService();
			linkService.openRetailPage(request);
		} catch (NotInitializedException e) {
			Log.v(TAG, e.printStackTrace());
		}
	}
});

In the OpenSearchPageRequest, you can also specify Brand and SortOrder as well. For information about brands, sort orders, and categories, see [Mobile Associates API Search Categories][mobile-associates/mas-search-categories].