Starting navigation with android intent - android

I have method which start navigation on external app. Method working well with google maps and sygic. But users started to reporting they can open navigation even with Waze but no data is transported via intent (so they see only waze main screen).
I found right uri to launch waze but then I'll loose other options.
private fun startNavigation(lat: Double, lon: Double) {
val uri = "google.navigation:q=$lat,$lon" //google maps, sygic - ok, waze - fail
//val uri = "waze://?ll=$lat,$lon&navigate=yes" //waze only
//val uri = "google.navigation:q=$lat,$lon&ll=$lat,$lon&navigate=yes" //google maps, waze - ok, sygic - fail
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(uri)))
}
I missing something here? Is there any universal option how to support all possible applications or should I make custom bottom sheet to handle it by myself for most used?

Unfortunately there is no general intent for navigation. So you must take care of apps you want to support and open them via Intent.ACTION_VIEW
Try setting waze url like this:
val wazeUrl = "https://waze.com/ul?ll=$latitude%2C$longitude&navigate=yes"
For further information have a look at this medium post

Related

Show a dialog before choosing which Maps application

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.

Android 12 open link in Chrome intent

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
}

Open URL on phone from watch face

I have a watch face that I've created and I was looking into adding an "About" screen in the watch settings (on the watch). This screen would show the current version and show a button to open a URL leading to a changelog. I want the user to be able to click the button on their watch, and have it open the specified URL on the phone.
Is this possible without me creating a mobile companion application?
You can do this if the watch is running Android Wear 2 using a RemoteIntent, as such:
Intent intent = new Intent(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(Uri.parse("http://www.google.com"));
RemoteIntent.startRemoteActivity(context, intent, null);
...replacing http://www.google.com with your desired URL, of course.
AFAIK, there's no way to accomplish this on Wear 1.x without sending a message to your handheld app and programming it to open the URL itself.
Note the new way to do this is with RemoteActivityHelper:
val remoteActivityHelper = RemoteActivityHelper(context, Executors.newSingleThreadExecutor())
val result = remoteActivityHelper.startRemoteActivity(
Intent(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(
Uri.parse("http://www.google.com/")
),
null
)
and if you want to show the nice "Open on phone" animation, use ConfirmationActivity:
startActivity(
Intent(this, ConfirmationActivity::class.java)
.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION))

How to launch route activity on google maps without destination

How can I launch route activity on google maps from my app without specifying the destination? I am using:
Uri gmmIntentUri = Uri.parse("google.navigation:q=<>");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Bad behavior :
But the "to" field in google maps has "<>" string, and if I write:
Uri gmmIntentUri = Uri.parse("google.navigation:q=");
But this not working.
The idea is:
Right behavior:
There doesn't seem to be a way for you to specifically go to a specific Activity in the official Maps app (empty destinations). If you look at the Google Maps Intent, it exposes several intents that can launch Maps to display, search, navigate and use Street View. For searching location, you are required to have coordinates or optional queries and labels.

How to launch Amazon Shopping app in Android app?

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

Categories

Resources