Sending email via Intent
-
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(); } }
-
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(); } }
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);
-
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(); } }
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
-
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
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.
-
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.
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 ofstartActivityForResult()
?"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
-
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 ofstartActivityForResult()
?"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
yes, I did try startActivity. Same effect.