Question

In my Android app, I have a button with the background image of an Amazon.com product (let's say a shirt or something), and when clicked I would like it to open in the Amazon app (com.amazon.mShop.android) if is already installed rather than in the browser, and in the browser if the app is not installed.

I have been able to find how to add a deep link to a specific Amazon client app, but not how to link to a specific item that would open with open with the Amazon app.

Currently, my click listener opens in a browser by doing the following:

b3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse(urlOfItemOnAmazonSite));
            startActivity(intent);
        }
    })
Was it helpful?

Solution

The Amazon developer's home page is probably the best place for this answer. This may be a good start: https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs/deeplink#Link%20Configuration. Here they explain how to construct the Uri you'll need to use to set the Intent data.

Of course, you may want to be careful and wrap startActivity in a try/catch in case Amazon isn't installed and it throws an ActivityNotFoundException

OTHER TIPS

You can simply do the following:

b3.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
       Uri uri=Uri.parse(productUrl);
       Intent intent=new Intent(Intent.ACTION_VIEW,uri);
        startActivity(intent);
    }
})

//Note extract url of product store in var productUrl(or any other var) and //parse it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top