Skip to content

Instantly share code, notes, and snippets.

@mustafasevgi
Created March 3, 2015 13:38
Show Gist options
  • Save mustafasevgi/8c6b638ffd5fca90d45d to your computer and use it in GitHub Desktop.
Save mustafasevgi/8c6b638ffd5fca90d45d to your computer and use it in GitHub Desktop.
Send sms android kitkat and above or below version
private void sendSMS() {
String text = getSMSContent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); // Need to change the build to API 19
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else // For early versions, do what worked for you before.
{
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
sendIntent.putExtra("sms_body", text);
startActivity(sendIntent);
}
}
@mustafasevgi
Copy link
Author

Send sms specific phonenumber
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(Uri.parse("smsto:phonenumber"));

Copy link

ghost commented Jul 6, 2015

return to the app
sendIntent.putExtra("exit_on_sent", true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment