Skip to content

Instantly share code, notes, and snippets.

@mancdevcarl
Last active December 17, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mancdevcarl/5624906 to your computer and use it in GitHub Desktop.
Save mancdevcarl/5624906 to your computer and use it in GitHub Desktop.
ACTION_SENDTO Intent SMS and Email
try {
if (v == findViewById(R.id.emailbtn)) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,Uri.fromParts("mailto", "@", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "TITLE");
emailIntent.putExtra(Intent.EXTRA_TEXT, "TEXT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
} else if (v == findViewById(R.id.smsbtn)) {
Uri uri = Uri.parse("smsto:");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "BODY");
startActivity(it);
}
} catch (Exception ex) {
ex.printStackTrace();
// the try{}catch{} block is incase a default app doesnt exist on the device
Toast toast = Toast.makeText(getApplicationContext(),"No default app found!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment