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.
Related
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
In my application i want to open the gallery and choose an image from it. So i do
gallery.setOnClickListener {
val imageIntent = Intent().apply {
type = "image/*"
action = Intent.ACTION_PICK
}
startActivityForResult(
Intent.createChooser(imageIntent, "Select an image"), IMAGE_REQUEST_CODE
)
}
However, when i choose an image i want the user to be able to preview the image that he selected before i get it in the ActivityResult. In some devices and some apps (Google Photos) they do this by default, but in other devices i can't get that feature.
How can i have this functionality by default in every device?
How can i have this functionality by default in every device?
You can't.
You are starting an activity from a third-party app. What the third-party app does is up to the developers of the third-party app.
In some cases, there are Intent extras that provide hints as to what we want the third-party app to do. In this case, there is no standard "please provide a full-screen preview" extra. And, even if there were, there is no requirement for any given ACTION_PICK activity to pay attention to that extra.
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))
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
hi everybody i've a little problem..i'm trying to share a text using google plus app, but the lastest version give me a problem.
when i call with an intent "com.google.android.apps.plus", android display me this dialog
so if i choose the first one, text will be shared correctly, but the second one do nothing.
if the app is not intalled i redirect the user to the market, at g+ download page (this work fine)
if (v == plus) {
social(2);
targetedShareIntent.putExtra(
android.content.Intent.EXTRA_TEXT, user);
targetedShareIntent
.setPackage("com.google.android.apps.plus");
startActivity(targetedShareIntent);
}
"v" is a button and social check if app is installed
any sugestion?
both options open google+ application?
I suppose show two options because google+ app have two activities with category.LAUNCHER.... the app and the chat app
PSDT: sorry for my bad english!
I was able to get the G+ dialog to launch with the following code (after querying the package manager to make sure the app was actually installed and passing in the currentContext as a parameter):
Intent appIntent = new Intent(Intent.ACTION_SEND);
String shareText = "Share text goes here";
appIntent.setType("text/plain");
appIntent.putExtra(Intent.EXTRA_TEXT, shareText);
//Filters so only the G+ app will launch
appIntent.setPackage("com.google.android.apps.plus");
try {
currentContext.startActivity(appIntent);
} catch (android.content.ActivityNotFoundException e) {
Log.d(e.getMessage());
}
Drove me bananas figuring this out, so I figured I'd try to save someone else the hassle.