问题
I'd like to be able to launch the Amazon Shopping app from my android application. How is this possible? What parameters would need to go into the Intent? Here is a link to the Amazon Shopping app: https://play.google.com/store/apps/details?id=com.amazon.mShop.android.shopping&hl=en
In addition, how would it be possible to pass a deep-link parameter so that it lands on a specific product page? Thank you!
回答1:
I'd like to be able to launch the Amazon Shopping app from my android application. How is this possible? What parameters would need to go into the Intent?
You can use PackageManager#getLaunchIntentForPackage
startActivity(getPackageManager().getLaunchIntentForPackage("com.amazon.mShop.android.shopping"));
In addition, how would it be possible to pass a deep-link parameter so that it lands on a specific product page?
It depends on whether Amazon app implements deep link and exposes intent-filter
to external app. I assume it's not possible, but maybe you can ask Amazon.
回答2:
The problem with using
startActivity(getPackageManager().getLaunchIntentForPackage("com.amazon.mShop.android.shopping"));
is that it assumes that the user has the android app installed. If it's not there it will fail. So, I decided to use a uri. My first attempt was to use the amazon documentation Link to Amazon from within Your App
but that didn't work so well. It looks like it only searches for apps, not all products. When I tried to use the asin parameter for a non-app product it did not work. So I did the following and it gave me what I wanted.
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.amazon.com/Red-blue-Anaglyph-3D-Glasses-game-Extra/dp/B003LWYGPE/ref=pd_sim_23_1?_encoding=UTF8&pd_rd_i=B003LWYGPE&pd_rd_r=3REW4891981B4R6WAB66&pd_rd_w=NcbkD&pd_rd_wg=GDhOT&psc=1&refRID=3REW4891981B4R6WAB66"));
startActivity(browserIntent);
It opened the search in a browser with an option to open the app. I suppose one could attempt to go the amazon app route first and, if it fails, open this browser version.
来源:https://stackoverflow.com/questions/33837550/how-to-launch-amazon-shopping-app-in-android-app