Share Email intent or Generic message intent - android

I have 2 types of Intents for sharing. One for simple generic messaging like SMS/Slack etc. and Another one for email. What I can't seem to figure out is how to make where I can find a way to resolve what someone has chosen via the chooser and use the appropriate intent.
(This would be done via pressing the share button and all send options would show in the chooser
Any help with this would be awesome.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
Intent chooser = Intent.createChooser(shareIntent,"");
My thought was when resolving the chooser I could see if it was an email type but that doesn't seem to work either.

Once you have fired off an Intent, control of what happens is outside your control. The chooser will not provide a callback to your app once the user chooses an action- instead the system will pass the intent you launched on to the selected application.
As discussed in How to filter specific apps for ACTION_SEND intent (and set a different text for each app), if you want to customize the chooser you have a few options. You can:
Use Intent.EXTRA_INITIAL_INTENTS to surface other intents in addition to the default option.
Create your own custom chooser that provides the behavior you want
The first option may not be ideal because the ordering of options might not be want you want.
The second option provides much more control, but is a lot of work to maintain, particularly if you want newer platform features like directly sharing with a contact.
Another option would be to change your UI to offer separate "share" and "email" options, then use the default intents for each.

Related

How to configure the android intent actions in android manifest

I have a webview in my app, on trying to do actions like making a call (Tapping call button from results displayed in webview), sending mails and other actions, my webview doesn't perform those actions
I Found a solution to add the intent actions in my web view activity as
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent)
Instead of doing so is there any way to add in the android manifest file
or Is there any way to turn on all of the intent actions for the webview so that
there wont be further issues in handling the actions
Can someone help me on this pls
Your answer seems to me a bit strange, I think you are a bit confuse about the difference between Intent and manifest permission. The first one are the system used by android to let app communicate with each other, the second one allow you to use some feature of the device like wifi and direct phone call that need the explicit agreement of the user to be used (the prompt that popup when you make the first install of an app).
With this clarification it is clear that if you want to do something that require another app you will have to make an Intent. This Intent, if well formed, will be elaborated by the os that will take care of sending it to the correct application able to accomplish the Intentrequirement.
So the answer to your question, as far as i know, is no, you have to use intent if you have the need of calling external app. It's also a good practice to set in the manifest only the permission really needed by the app, this way the user know what the app really can do and and what it can't do.
Hope i understand your question and answer it.

Android intent opposite of setComponent

I know I can force an intent to use a specific application/activity by using intent.setComponent(). But is there a way to say that it should not use a specific app/activity?
Why I need this:
My application will be able to respond to several urls (like http://www.companyname.com/something/12345). If my app launches cause of an Intent to this url, I'll check if I have the needed data to handle this. (In my example, something with id 12345). If I'm not able to do something useful with the intent, I create a new Intent with the same data, so the user can try to view the content in its browser.
This is the moment my problem occurs. When I start my newly created intent, my app appears again in the list of apps that can handle this. But I already know that my app can't do anything with this intent. The user already knows that my app can't handle the intent, but still it'd be nice if my app just didn't appear in this list.
Thanks in advance.
A possible solution that works is when creating the new intent, instead of intent.setData(uri) I do intent.setDataAndType(uri, "text/html").
This causes that my app disappears from the list. At the moment it's a solution that works :) But still I'd like to know if there are better ways to achieve this result.
You may use Intent-Filters for your app and set up the URI with wildcards as you need, see here for more information. With some additional info via an action or category, you may ensure, that your app it the only one (not) matching against the intent.

How to attach an image with sms without showing Action chosser in android?

I have to attach an image file with the sms on button click i use this code
final Intent smsIntent = new Intent(android.content.Intent.ACTION_SEND);
smsIntent.putExtra("sms_body", "Hello World!");
smsIntent.putExtra("address", "0123456789");
smsIntent.putExtra(Intent.ACTION_ATTACH_DATA,screenshotUri);
smsIntent.setType("image/png");
startActivity(smsIntent);
But this shows a chooser to choose an action like Facebook,Email,Messages etc.
But i do not want any the chosser view it will directly show the message intent with attached file.
What you are looking for cannot be done using implicit Intents. Because that is how the Android system is designed to handle implicit intents. If you want your intent to be handled by a specific application then you have to make them explicit, i.e., specify a component that has to handle the intent. But when you use explicit intents to handle any situation such as yours, then there is a great chance of your app to break when the specific component (i.e. Application) doesn't not exist in the target device. Android is being adopted by several OEMs, therefore each of them tend to replace the stock Messaging application with their own. So what seems to work on one device may not work on the other.
If you want to achieve what you want then you may have to get the list of Messaging applications on various devices, (you can find the stock Android app's component name from the emulator itself). And use the PackageManager to find if the component exists. If it does, the start and explicit intent, in which you won't receive an IntentChooser. If the component doesn't exist send an implicit intent.
You can learn more about intents from here.
Determining if an Activity exists on the current device? - This post will help you to find if the target component exists.

What does an Android Intent do with its URIs?

Reading through the document and a couple others, none really specified what an Intent does with the URI that it is passed. I'm simply curious as to what happens when it gets a URI. I know it depends on the scheme, so if the scheme was http, does it then attempt to open that web URI?
I ask since I'm trying to consume RESTful API that sends data back in JSON format. Having it open the URI for me when trying to pass the data from one Activity to another rather than making the HTTP call myself via HttpClient would be nice. Not a big deal but I was just curious if that is how works.
An Intent is just an object ... it does nothing with the URI. An Intent is used in function calls like startActivity(), sendBroadcast(), etc.
For example, when you pass an Intent to startActivity(), that Intent object is made available to the Activity. The Activity can interpret the URI as it pleases.
Android also uses Intent Filters to help route intents to various installed activities, these intent filters may inspect the URI.
Review http://developer.android.com/guide/components/intents-filters.html for all the info.
It's not entirely clear what you mean, however the behavior of Intents is basically dictated by the Android package manager. You can think of an Intent as being a procedure call: you specify someone to handle the Intent, along with some additional data (parameters), possibly some category, etc...
The Android package manager looks at your intent and basically asks the question "what app on the system is prepared to consume and handle this intent?" The system then opens up that app (if it is not already resident in memory), and then throws the intent at the app. Note that there are cases where there exist some possibility of ambiguity among intent handlers: multiple apps could be prepared to handle the intent. You can sometimes see this in the form of the user being asked to select what app should handle the intent (and the user can select a default one).
The dynamic semantics of how intents are handled depends, of course, on the set of apps installed on the system, and may change depending on the type of app installed. It sounds like, in your case, you are mostly concerned with intents that have an ACTION_VIEW action associated with them. In the general case, things that look like URLs will be "caught" by the browser (though there is no guarantee that this be the case!), and the package manager will look at the structure of the URI and say "hey, this looks like it should be handled by app X," I'm going to send this URL to it. (And, of course, new apps can change this behavior by registering other intent filters..)
An intent is an abstract description of an operation to be performed.uri specific data that intent has to do operation on it:
Intent Structure
The primary pieces of information in an intent are:
action: The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
data: The data to operate on, such as a person record in the contacts database, expressed as a Uri.
Some examples of action/data pairs are:
ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1".
ACTION_VIEW tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is
considered the most reasonable thing for a particular URI.
ACTION_VIEW content://contacts/people/ -- Display a list of people, which the user can browse through. This example is a typical
top-level entry into the Contacts application, showing you the list of
people. Selecting a particular person to view would result in a new
intent { ACTION_VIEW content://contacts/N } being used to start an
activity to display that person.
So you can see that same Action with different data/uri perform different Action on data operate on.

Android Override Explicit Intent

My app needs to have a intent-filter that responds to a Intent that has it's component set (a explicit intent.) Here is a example.
Intent i = new Intent();
i.setClassName("com.compareeverywhere","com.compareeverywhere.ScanActivity");
startActivity(i);
Just a simple intent-filter will not do - because the Intent is made for a specific component (Activity,) it just launches that without looking for intents at all. Is there a way to do this?
Thanks, Isaac Waller
P.S: Please don't reply "No."
No.
:) That being said, imagine what would happen if Android allowed people to hijack Intents for specific components. Don't like a competitor's app? Just have yours hijack his main Activity with your own to display porn. Intents can specify specific components specifically because the authors don't want others to be able to replace them.
You have two options. If this is your own code, replace it with a generic intent, or if it belongs to someone else, contact them, and ask nicely for them to change it to a generic intent along with some good reasons why that is necessary.

Categories

Resources