-1

I am creating an app in which user can share "something" by clicking on a share button. The steps to share "something" are:

  1. On clicking the share button the contact list should open
  2. By selecting a contact (with valid a email address) the data should be sent directly to the selected contact from the sender's default email address(Gmail) without popping up a window for selecting an email client like "Gmail", "Dropbox" etc..

I managed to get the email id of contact with the help of http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/ but after selecting a contact I get a pop up for selecting an email client like "Gmail", "Dropbox" etc..

here is my code so far

       if( email.length() != 0 )
       {
            Intent sharingIntent = new Intent(
                   android.content.Intent.ACTION_SEND );
            sharingIntent.setType("message/rfc822");
            String shareBody =
                            "Hey buddy listen to this station it is awesome\n"
                            + mNowPlayingSong.mAudioUrl;
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                           "I liked this song" );
           sharingIntent.putExtra(                                                     
                          android.content.Intent.EXTRA_TEXT, shareBody );
           String emailAddressList[] = {email};
           sharingIntent.putExtra(Intent.EXTRA_EMAIL, emailAddressList );
           startActivity( sharingIntent );
ethan
  • 780
  • 7
  • 20
shankey
  • 333
  • 2
  • 7
  • 18
  • 1
    What you're wanting to do isn't really possible. I mean, it would be possible to open Gmail directly, but they would still have to send it from within the gmail app anyway. And I personally think that you should let the user choose. If you want to send the email on your own, you could communicate with a web server to do so - that is if you have your own domain/web server or can find some 3rd party service. – Reed Dec 21 '11 at 13:08
  • Its not like , it is not possible, because I have seen app which does like what I want. So I am sure that there is something solution and I am trying to find it a lot. so please try to help, and also tel me how can I open Gmail directly ? – shankey Dec 21 '11 at 13:20
  • 1
    Why don't you want your users to be able to choose which email client or address they use? Have you considered the possibility that some people use different email addresses to communicate with different groups of people? Also, you can launch any other application with the right intent. Here is the official documentation, you can google for the specifics about launching gmail yourself: http://developer.android.com/guide/topics/fundamentals.html#ActivatingComponents. – ethan Dec 21 '11 at 13:47
  • @ethan : My client don't want that..I googled but I didn't found expected solution. please let me know If you found something. – shankey Dec 21 '11 at 13:55
  • Your client is an idiot. This may stun your client, but not everybody uses Gmail -- their market share is interesting but not *that* big. Even if a user has a Google account for the purposes of using the Android Market, the user may not be using Gmail for email. Please allow **the user** to choose how they send this information, including what mail account and mail application to use. – CommonsWare Dec 21 '11 at 14:38
  • My client is Idiot but ,I cant do anything. – shankey Dec 21 '11 at 14:48

1 Answers1

3

You cannot send email silently with the default application. You can only create an intent that will call an activity and that will fill in all the fields.

Other possibility is to embed your own email client into yours application. In this case, if a user provides credentials then you'll have a possibility to send a email silently. To implement the second options check this: Sending Email in Android using JavaMail API without using the default/built-in app

Community
  • 1
  • 1
Yury
  • 20,618
  • 7
  • 58
  • 86