Last active
December 17, 2015 14:29
-
-
Save mancdevcarl/5624906 to your computer and use it in GitHub Desktop.
ACTION_SENDTO Intent SMS and Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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