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!
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.
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.
if you want to deeplink to the detail page ,first you should find the product_id for amazon. and try this scheme:
com.amazon.mobile.shopping://content/item?id=<some valid id>
All code trying here is:
jumpUrl?.let { it ->
try {
val intent = Intent(Intent.ACTION_VIEW)
val findStr = "/dp/"
val findIndex = it.indexOf(findStr)
if (findIndex != -1) {
intent.data = Uri.parse(
"com.amazon.mShop.android.shopping://www.amazon.com/products/${
it.substring(
findIndex + findStr.length
)
}"
)
} else {
intent.data = Uri.parse(it)
}
intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK
intent.let { tent ->
context.startActivity(
tent
)
}
} catch (exception: ActivityNotFoundException) {
exception.printStackTrace()
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(it)
intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}
}
My references is : iPhone iOS Amazon Scheme / URI Not Working Anymore amzn:// version 4.3.1 Deep Linking
Related
I am making a list of stores near me on a map using google maps. How to get a popup where when I select one of these stores it will choose one of the Maps apps downloaded on the phone. When I research about it, I can't find any results. For example, when we want to open a PDF, a popup appears on the device about which application to choose. I want to do similar to this. For example, now I have Yandex and Google Maps application on my phone. I have to make a popup that will select either one. The code below opens only the Google Maps application directly.
fun openMapApp(office: StoreOffice) {
weakReference.get()?.run {
val location = "${office.latitude},${office.longitude}"
val uri = Uri.parse("geo:${location}?q=${location}(${Uri.parse(office.vendorName)})")
val intent = Intent(Intent.ACTION_VIEW, uri)
val chooser = Intent.createChooser(intent, resources.getString(R.string.chooser_title))
try {
startActivity(chooser)
} catch (e: ActivityNotFoundException) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.common_warning)
.setMessage(R.string.app_not_found_message)
.build()
}
}
}
From your question, I believe you want a way to choose a navigation app from the list of navigation apps on your phone.
Check out this answer from the question Android intent chooser for navigation apps. It should be of help.
I want to open link like "intent://qr.nspk.ru/url-something/#Intent;scheme=someScheme;package=com.example.android;end#Intent;scheme=someScheme;end" from an android application.
If I write something like this:
val i = Intent(Intent.ACTION_VIEW, Uri.parse(androidUrl))
startActivity(i)
I get this error:
No Activity found to handle Intent { act=android.intent.action.VIEW
dat=intent://qr.nspk.ru/url-something/#Intent;scheme=someScheme;package=com.example.android;end#Intent;scheme=someScheme;end
But If I go to this link from browser, it opens and it open an app that I need. Can you help me to understand why I can't open link from app and how to fix it?
The intent: scheme is used for the browser to encode an Android Intent. If you want to use this URL from an Android app, you need to create an Intent from the URL like this:
val i = Intent.parseUri(androidUrl, Intent.URI_INTENT_SCHEME)
startActivity(i)
Since Android 12, links can only be opened with one "approved" app.
As of right now I have my app's supported urls defined in AndroidManifest.xml as intent-filter.
Also I have a button in my app that creates an intent to open a link in browser.
With Android 12 limitations though, if I have the url tied to my app, clicking the open in browser button does re-open my app, which is quite an unwanted behavior.
Is there a way to force a url open in chrome (or other browser)?
I checked the android developer documentation but have not found anything about it.
Thank you
You can specify the default browser explicitly as the package to handle your intent:
val defaultBrowserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://"))
// This would be Chrome if it's the selected default browser
val defaultBrowserPackageName = packageManager.resolveActivity(
defaultBrowserIntent,
PackageManager.MATCH_DEFAULT_ONLY
)
?.activityInfo
?.packageName
val yourIntent = Intent(context, ...).apply {
package = defaultBrowserPackageName
}
I want to pass a link of a video and want YouTube app to play that video directly and I want to use following code:
btn3.setOnClickListener {
val i = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube")!!
startActivity(i)
}
I don't want to use following code:
startActivity(Intent(Intent.ACTION_VIEW,Uri.parse("link of video")))
Instead of querying the launch Intent, which does not take any arguments, you can call setPackage() on your ACTION_VIEW Intent to tell the OS to open the desired app:
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("link of video")).apply {
setPackage("com.google.android.youtube")
}
You should be careful though, in case the YouTube app is not installed on the device your code will throw an ActivityNotFoundException. The best way to guard against this is using PackageManager.queryIntentActivities() which will return an empty list if there are no Activities that can handle the Intent.
In the app I am working on I want to support Netfilx streaming. I intend on doing this by simply starting Netflix and passing a specific URI so it plays a specific video when started. Simple right? Well, the issue is I'm not sure how to pass the video id info in the Intent I use to start the Activity.
I've read the post here , but am unsure where to use this. I used Intent.setData() since it accepts a URI, but to no avail.
Here is what I have been doing (I am hard coding the movie data, this is just for testing purposes) :
// the Netflix intent
Intent intent = getPackageManager().getLaunchIntentForPackage("com.netflix.mediaclient");
//the uri
Uri uri = Uri.parse("http://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
intent.setData(uri);
//launches but does not go to the video
startActivity(intent);
I've also tried using the URI protocol in the link above like so:
Uri uri = Uri.parse("nflx://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
but still am not seeing the video play.
I feel like I am missing something simple here, although I have had very little luck Googling for this, I could find next to nothing about starting the Netflix Android app from another application. The Netflix developer resources don't have any info on this.
Does anyone have any suggestions on how I can do this or where I should be looking for documentation on this? Any help would be appreciated. Thanks much!
Just some Android Apps intent names to help anyone.
Format: appName, packageName, className
Skype: com.skype.raider, com.skype.raider.Main
Netflix: com.netflix.mediaclient, com.netflix.mediaclient.ui.launch.UIWebViewActivity
ESexplorer: com.estrongs.android.pop, com.estrongs.android.pop.view.FileExplorerActivity
Youtube: com.google.android.youtube,com.google.android.youtube.HomeActivity
Chrome: com.android.chrome,com.google.android.apps.chrome.Main
VLC: org.videolan.vlc, org.videolan.vlc.gui.MainActivity
MBOXSettings: com.mbx.settingsmbox, com.mbx.settingsmbox.SettingsMboxActivity
I've managed to do this. With the following code. First you need the movieId (or videoId) for netflix, then compose the URL to watch.
String netFlixId = "43598743"; // <== isn't a real movie id
String watchUrl = "http://www.netflix.com/watch/"+netFlixId;
Then with this intent
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.launch.UIWebViewActivity");
intent.setData(Uri.parse(watchUrl));
startActivity(intent);
}
catch(Exception e)
{
// netflix app isn't installed, send to website.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(item.url));
startActivity(intent);
}
I haven't tried with TV Shows yet. But this works beautifully. If you want to send to the profile page of the movie.. Send it to a url formatted this way
http://www.netflix.com/title/324982
I also found out how to search for a title.
try {
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.search.SearchActivity");
intent.putExtra("query", item.label);
startActivity(intent);
}
catch(Exception e)
{
Toast.makeText(this, "Please install the NetFlix App!", Toast.LENGTH_SHORT).show();
}
Here is how to start a movie from an ADB command for com.netflix.mediaclient
adb shell am start -n com.netflix.mediaclient/.ui.launch.UIWebViewActivity -a android.intent.action.VIEW -d http://www.netflix.com/watch/60000724
I still can't find a way to do it for com.netflix.ninja (Netflix for Android TV)