sendmail - Android: Sending a Mail/SMS/Tweet with Intent.ACTION_SEND / requestCode / resultCode? -


I am using the following code:

  Send the intentMelentent = new intent (intent ACTION_SEND); SendMailIntent.putExtra (Intent.EXTRA_SUBJECT, getString (R.string.Share_Mail_Subject)); SendMailIntent.putExtra (Intent.EXTRA_TEXT, getString (R.string.Share_Mail_Text)); SendMailIntent.setType ("text / plain"); StartActivity (Intent.createChooser (sendMailIntent, "Email / SMS / Tweet?"));  

Then I want to be able to differentiate between them: 1. My user actually sent email / SMS ... or 2. My user actually pushed the back button Given ... nothing else is sent.

Is there any way to make this difference?

=> Should I start the activity with the introduction activity? And click on requestCode / resultCode withActivityResult ...

=> What should I expect the king of the result? How to catch it correctly? Where do I put these lines? A snippet of code will be very useful.

Thanks in advance.

hub

I have a feeling that when you have asked about this question , Then it's been a while and Android has changed a lot during this time. I'm not sure if you are still looking for an answer, but if you are, you can do it with the new Intent.createChooser () method, which is one third Pending INTent.getIntentSender () logic, and a broadcast recipient . Here's how you do it:

Send intent mail intent = new intent (int. Action_sand); SendMailIntent.putExtra (Intent.EXTRA_SUBJECT, getString (R.string.Share_Mail_Subject)); SendMailIntent.putExtra (Intent.EXTRA_TEXT, getString (R.string.Share_Mail_Text)); SendMailIntent.setType ("text / plain"); Intent Receptor = new intent (this, BroadcastTest.class); Receiver Input extras ("exam", "exam"); Pending pending vertical = pending = Pending Iotbrocost (this, 0, receiver, pending.FLAG_UPDATE_CURRENT); Intent Chooser = Intent. Buyer Selector (Intent, "Trial", PendingIntext.GETINenter ()); StartActivity (selector);

Note that my receiver objective was the goal of BroadcastTest class which extends to BroadcastReceiver . When the user selects an application from the selector, then onReiveive will be called in BroadcastTest and if the user presses back, onReiveive will not be called. In this way, you can check that the user has actually sent an email / SMS / Twitter or if he is pressed back or not, for example, if this is my BroadTest class:

< Pre> Broadcast Test broadcasts broadcasts the receiver {@ Override Public Records on Receive (context reference, intention intended) {for (string key: Intent.getExtras (). KeySet ()) {Log D. GetClass () .GetSimpleName (), "" + intent.getExtras (). Get (key); }}}

You will find something like ComponentInfo {org.telegram.messenger / org.telegram.ui.LaunchActivity} in your logged in user. Using the application telegram key and android.intent.extra.CHOSEN_COMPONENT , you should be able to find the user selected. Also, do not forget to declare the broadcaster receiver in your manifest.

Another way is to PackageManager and queryIntentActivities () to make your own selector this allows you to allow the program to get user selection . The method is described in StackOverflow post.

To resolve your question about startActivityForResult from Android source, you can see that activity which chooses between Intents does not setResult () Not at all, if you try to capture the result code in onActivityResult , then it is always 0 (< Code> RESULT_CANCELED ). Thus, by using startActivityForResult , you can not determine that the user selected an option or pressed back.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -