Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Sending email via Intent

Sending email via Intent

Scheduled Pinned Locked Moved Android
questionhelpworkspace
6 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 8225180
    wrote on last edited by
    #1

    I have and app which requires sending emails with attachments. This app contains many activities. Within one activity, I send an email using the following intent: startActivityForResult(Intent.createChooser(emailIntent, "Email"), EMAIL_REQUEST); This works fine. The email is sent. The problem: After email is sent, the app loads/goes to the startup activity, not the activity from which the email was sent. (Also note: onActivityResult is never called) How can I return to the activity which sent the email? Code fragment:

        Intent emailIntent = new Intent(Intent.ACTION\_SEND);
        emailIntent.putExtra(Intent.EXTRA\_EMAIL, new String\[\]{to});
        emailIntent.putExtra(Intent.EXTRA\_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA\_TEXT, message);
        emailIntent.setType("message/rfc822");
    
        File publicFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\_PICTURES);
        File inFile = new File(publicFolder, "snapshot.PNG");
        if (inFile.exists() && inFile.canRead()) {
    
            Uri uri = Uri.fromFile(inFile);
            emailIntent.putExtra(Intent.EXTRA\_STREAM, uri);
    
            try {                startActivityForResult(Intent.createChooser(emailIntent, "Choose an Email client :"), EMAIL\_REQUEST);
                isSuccess = true;
            }
            catch (Exception e) {
                Toast.makeText(getApplicationContext(), "startActivity() exception thrown while sending email", Toast.LENGTH\_SHORT).show();
           }
        }
    
    L D 2 Replies Last reply
    0
    • M Member 8225180

      I have and app which requires sending emails with attachments. This app contains many activities. Within one activity, I send an email using the following intent: startActivityForResult(Intent.createChooser(emailIntent, "Email"), EMAIL_REQUEST); This works fine. The email is sent. The problem: After email is sent, the app loads/goes to the startup activity, not the activity from which the email was sent. (Also note: onActivityResult is never called) How can I return to the activity which sent the email? Code fragment:

          Intent emailIntent = new Intent(Intent.ACTION\_SEND);
          emailIntent.putExtra(Intent.EXTRA\_EMAIL, new String\[\]{to});
          emailIntent.putExtra(Intent.EXTRA\_SUBJECT, subject);
          emailIntent.putExtra(Intent.EXTRA\_TEXT, message);
          emailIntent.setType("message/rfc822");
      
          File publicFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\_PICTURES);
          File inFile = new File(publicFolder, "snapshot.PNG");
          if (inFile.exists() && inFile.canRead()) {
      
              Uri uri = Uri.fromFile(inFile);
              emailIntent.putExtra(Intent.EXTRA\_STREAM, uri);
      
              try {                startActivityForResult(Intent.createChooser(emailIntent, "Choose an Email client :"), EMAIL\_REQUEST);
                  isSuccess = true;
              }
              catch (Exception e) {
                  Toast.makeText(getApplicationContext(), "startActivity() exception thrown while sending email", Toast.LENGTH\_SHORT).show();
             }
          }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to edit your question and show a bit more of the code and indicate exactly where the problem occurs. Please ensure that you use <pre lang="java"></pre> tags around your code, so it is readable like:

      startActivityForResult(Intent.createChooser(emailIntent, "Email"), EMAIL_REQUEST);

      1 Reply Last reply
      0
      • M Member 8225180

        I have and app which requires sending emails with attachments. This app contains many activities. Within one activity, I send an email using the following intent: startActivityForResult(Intent.createChooser(emailIntent, "Email"), EMAIL_REQUEST); This works fine. The email is sent. The problem: After email is sent, the app loads/goes to the startup activity, not the activity from which the email was sent. (Also note: onActivityResult is never called) How can I return to the activity which sent the email? Code fragment:

            Intent emailIntent = new Intent(Intent.ACTION\_SEND);
            emailIntent.putExtra(Intent.EXTRA\_EMAIL, new String\[\]{to});
            emailIntent.putExtra(Intent.EXTRA\_SUBJECT, subject);
            emailIntent.putExtra(Intent.EXTRA\_TEXT, message);
            emailIntent.setType("message/rfc822");
        
            File publicFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\_PICTURES);
            File inFile = new File(publicFolder, "snapshot.PNG");
            if (inFile.exists() && inFile.canRead()) {
        
                Uri uri = Uri.fromFile(inFile);
                emailIntent.putExtra(Intent.EXTRA\_STREAM, uri);
        
                try {                startActivityForResult(Intent.createChooser(emailIntent, "Choose an Email client :"), EMAIL\_REQUEST);
                    isSuccess = true;
                }
                catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "startActivity() exception thrown while sending email", Toast.LENGTH\_SHORT).show();
               }
            }
        
        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        What are you doing in the onActivityResult() method?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        M 1 Reply Last reply
        0
        • D David Crow

          What are you doing in the onActivityResult() method?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          M Offline
          M Offline
          Member 8225180
          wrote on last edited by
          #4

          I have found a solution. The initial activity's onresume method is called after the email is sent. What I do is intercept it and perform a startactivity to load the activity which was responsible for sending the email.

          D 1 Reply Last reply
          0
          • M Member 8225180

            I have found a solution. The initial activity's onresume method is called after the email is sent. What I do is intercept it and perform a startactivity to load the activity which was responsible for sending the email.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Without further investigation, that sounds more like a workaround than a solution. I have an app that sends an email, and it requires no special code to return right where it was prior to sending the email. Unless your app is doing something at the same time the email is being composed/sent, have you tried using startActivity() instead of startActivityForResult()?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            M 1 Reply Last reply
            0
            • D David Crow

              Without further investigation, that sounds more like a workaround than a solution. I have an app that sends an email, and it requires no special code to return right where it was prior to sending the email. Unless your app is doing something at the same time the email is being composed/sent, have you tried using startActivity() instead of startActivityForResult()?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              M Offline
              M Offline
              Member 8225180
              wrote on last edited by
              #6

              yes, I did try startActivity. Same effect.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups