0

I want to send some message to particular email ID. I set the to address and trying to send messages. it's working fine in Gmail App. but it's not working properly in the Mail App especially in Nexus 7(HTC one V also) what the reason behind?

Source Code

Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
emailIntent.setType("text/html");   
emailIntent.setData(Uri.parse("mailto:naresh.repalle@shoregrp.com"));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Price Check Guru Feedback");        
startActivity(Intent.createChooser(emailIntent, "Email:"));  

Updated Code

Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO); emailIntent.setType("text/html");

        //set the To address and Subject
        try
        {
            String strSubject = URLEncoder.encode("Price Check Guru Feedback","UTF-8");         
            //testing
            emailIntent.setData(Uri.parse("mailto:naresh.repalle@shoregrp.com"+ "?subject=" + strSubject));
        }
        catch (UnsupportedEncodingException e) 
        {
            e.printStackTrace();
        }           
        startActivity(Intent.createChooser(emailIntent, "Email:"));         
naresh
  • 10,332
  • 25
  • 81
  • 124

1 Answers1

0

Despite all the rumours which people spread on forums (and also here), not all Android e-mail apps support a mixture of SENDTO/mailto: and EXTRAs. Period. You've chosen an approach which is not supported by all apps (including K-9), that's all.

What seems to work is including the subject and body in the URL with ?subject= and &body=, using Uri.encode(). However, please be aware that the standard Android e-mail client V3.0 erases all + signs form such a message, probably due to wrong decoding.

Update: Okay so that's not your problem; lucky you. Of course, you can force the system to provide the chooser; have you not googled your problem? Although, if it does not fire, it means that the user chose Google mail over the proprietary e-mail program before.

class stacker
  • 5,357
  • 2
  • 32
  • 65
  • Then what should i do that supports all the Apps? – naresh Feb 04 '13 at 08:57
  • it's working fine in nexus 7 but in HTC one v is not working(i am unable to receive messages using mail app). i update the code plz check it once – naresh Feb 04 '13 at 10:03
  • @naresh Do yourself a favour and use Uri.encode() instead of URLEncoder.encode, as I wrote. -- Please describe what this means: _I am unable to receive messages using mail app_. You can't read your inbox? – class stacker Feb 04 '13 at 10:13
  • Can you please describe the behaviour. Simply saying _not working_ is not getting us anywhere. – class stacker Feb 04 '13 at 10:35
  • I used this Uri.encode, this time mail app is not working(means mail is not sent) in even any device(here i am using HTC one v, HTC wild fire s, nexus 7). Gmail app only working in both cases. But in First case(URLEncoder.encode), only HTC one V is not sent the mails using mail app but rest of them are working fine. then what should we do? – naresh Feb 04 '13 at 10:35
  • I presume you accidentially call `Uri.encode("Price etc", "UTF-8")`, which makes no sense. It must be `Uri.encode("Price etc")`. I was hoping you'd check the documentation first, but it looks like you didn't. It will be UTF-8 still. – class stacker Feb 04 '13 at 10:44
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23892/discussion-between-naresh-and-class-stacker) – naresh Feb 04 '13 at 11:05
  • @naresh I was offline. So did you succeed? – class stacker Feb 04 '13 at 14:45
  • @naresh And you don't have problems with `+` signs? – class stacker Feb 05 '13 at 12:15
  • ya it's coming but this time i ignore that. do you know how to solve this? – naresh Feb 05 '13 at 13:13
  • @naresh By using Uri.encode() instead of URLEncoder.encode, as I said. – class stacker Feb 05 '13 at 13:24
  • I have no idea what _we are not getting messages_ means. It's not specific enough to think of any potential problem sources. – class stacker Feb 05 '13 at 14:23
  • What i am saying is suppose we are trying to send messages using mail app but those messages are not received to recipients using Uri.encode(). I think now it's clear – naresh Feb 05 '13 at 14:31
  • @naresh Sorry, no. Because you don't say where the failure occurs. Do you see the e-mail app start and does it show the composed message? – class stacker Feb 05 '13 at 14:37
  • Stacker: yes it's start the email app and show the compose box but when i am trying to send message then it shows the toast message "sending..." and close the email app but that message is not yet received to the recipient. – naresh Feb 06 '13 at 06:29
  • @naresh And you think that is a problem with the Intent? – class stacker Feb 06 '13 at 12:23
  • Sorry i don't know that's what i posted. – naresh Feb 07 '13 at 06:15
  • Thanks. your solution is working fine. What happens is long back I created one folder for storing these mails. Accidentally that folder is overlapped with some other folder because of that i am unable see those mails. So i thought that those mail are not received. Now i saw that folder it's having lot mails previously test by me. sorry for this and thanks once again for activeness. – naresh Feb 07 '13 at 13:25