Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android intent to view an item using Amazon app on device rather than browser

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);
        }
    })
like image 665
Phillip Godzin Avatar asked Jan 11 '14 07:01

Phillip Godzin


1 Answers

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

like image 90
anddev84 Avatar answered Oct 28 '22 16:10

anddev84