How can one launch google maps app from another app with no action specified , like there are answers but all of one them specify the action to do, but if we just want to launch and let the user decide what he wants to do, how can we implement that ?
By creating an intent like this
// Create a Uri from an intent string. Use the result to create an Intent.
val gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988")
// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps")
// Attempt to start an activity that can handle the Intent
startActivity(mapIntent)
You can check google maps intents through the official documentation here https://developers.google.com/maps/documentation/urls/android-intents#kotlin
Related
I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.
I'm trying to understand Android Intents and I understand the concept of a Java event and an EventListener. Are these similar or the the same?
Intent in Android, is used to express an "intention" as the name implies, to perform an action over another component. One common usage of intent is to use it along with startActivity(intentObject), where the object contains the information(contexts) of the starting and openning activity, see below:
Intent intent = new Intent(context, MyActivityB);//pass the information(contexts of the current activity and the activity I want to open).
startActivity(intent);//Use startActivity method to start the activity defined in the object intent.
Other actions include: openning an app to send an email, open a social media, etc.
I want to access notification settings via intent on my application, how can I achieve this?
Check the following image
Intent intent = new Intent(); intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);
this is my sample codes but it gives me different output. What I want to see is a list of application exactly on the third image.
I am trying to share a link from my app with direct share. The share dialog must be like the image below with the most used contacts from messaging apps, like WhatsApp contacts.
This is the Intent structure which I am using for share the link:
Intent shareIntent = ShareCompat.IntentBuilder
.from(getActivity())
.setType("text/plain")
.setText(sTitle+ "\n" + urlPost)
.getIntent();
if (shareIntent.resolveActivity(
getActivity().getPackageManager()) != null)
startActivity(shareIntent);
And this is what my app shows:
Any idea how to achieve that?
You should use .createChooserIntent() instead of .getIntent()
Like this code below, you can use Intent.createChooser
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file://" + filePath);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
You should use .createChooserIntent() instead of .getIntent()
Docs: This uses the ACTION_CHOOSER intent, which shows
an activity chooser, allowing the user to pick what they want to before proceeding. This can be used as an alternative to the standard activity picker that is displayed by the system when you try to start an activity with multiple possible matches, with these differences in behavior:
You can specify the title that will appear in the activity chooser.
The user does not have the option to make one of the matching activities a preferred activity, and all possible activities will
always be shown even if one of them is currently marked as the
preferred activity.
This action should be used when the user will naturally expect to
select an activity in order to proceed. An example if when not to use
it is when the user clicks on a "mailto:" link. They would naturally
expect to go directly to their mail app, so startActivity() should be
called directly: it will either launch the current preferred app, or
put up a dialog allowing the user to pick an app to use and optionally
marking that as preferred.
In contrast, if the user is selecting a menu item to send a picture
they are viewing to someone else, there are many different things they
may want to do at this point: send it through e-mail, upload it to a
web service, etc. In this case the CHOOSER action should be used, to
always present to the user a list of the things they can do, with a
nice title given by the caller such as "Send this photo with:".
I am trying to capture the result of Intent.createChooser to know which app a user selected for sharing.
I know there have been a lot of posts related to this:
How to know which application the user chose when using an intent chooser?
https://stackoverflow.com/questions/6137592/how-to-know-the-action-choosed-in-a-intent-createchooser?rq=1
How to get the user selection from startActivityForResult(Intent.createChooser(fileIntent, "Open file using..."), APP_PICKED);?
Capturing and intercepting ACTION_SEND intents on Android
but these posts are somewhat old, and I am hoping that there might be some new developments.
I am trying to implement a share action without having it be present in the menu. The closest solution to what I want is provided by ClickClickClack who suggest implementing a custom app chooser, but that seems heavy handed. Plus, it seems like there might be some Android hooks to get the chosen app, like the ActivityChooserModel.OnChooseActivityListener.
I have the following code in my MainActivity, but the onShareTargetSelected method is never getting called.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, shareMessage());
sendIntent.setType("text/plain");
Intent intent = Intent.createChooser(sendIntent, getResources().getText(R.string.share_prompt));
ShareActionProvider sap = new ShareActionProvider(this);
sap.setShareIntent(sendIntent);
sap.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
#Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
System.out.println("Success!!");
return false;
}
});
startActivityForResult(intent, 1);
As of API level 22 it is now actually possible. In Android 5.1 a method (createChooser (Intent target, CharSequence title, IntentSender sender)) was added that allows for receiving the results of the user's choice. When you provide an IntentSender to createChooser, the sender will be notified by the chooser dialog with the ComponentName chosen by the user. It will be supplied in the extra named EXTRA_CHOSEN_COMPONENT int the IntentSender that is notified.
I am trying to capture the result of Intent.createChooser to know which app a user selected for sharing.
That is not possible.
Other "choosing" solutions, like ShareActionProvider, may offer more. I have not examined the Intent handed to onShareTargetSelected() to see if it contains the ComponentName of the chosen target, though the docs suggest that it should.
And, if for some reason it does not, you are welcome to try to fork ShareActionProvider to add the hooks you want.
The reason why createChooser() cannot be handled this way is simply because the "choosing" is being done by a separate process from yours.
I have the following code in my MainActivity, but the onShareTargetSelected method is never getting called.
ShareActionProvider goes in the action bar. You cannot just create an instance, call a couple of setters, and expect something to happen.