Skip to content

Instantly share code, notes, and snippets.

@almozavr
Created July 13, 2015 17:36
Show Gist options
  • Save almozavr/fc76f605c03822a3ee14 to your computer and use it in GitHub Desktop.
Save almozavr/fc76f605c03822a3ee14 to your computer and use it in GitHub Desktop.
Sms intent builder
public static Intent newSmsIntent(Context context, String body, String... phoneNumber) {
Uri smsUri;
if (phoneNumber == null) {
smsUri = Uri.parse("smsto:");
} else {
smsUri = Uri.parse("smsto:" + Uri.encode(TextUtils.join(",", phoneNumber)));
}
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent = new Intent(Intent.ACTION_SENDTO, smsUri);
intent.setPackage(Telephony.Sms.getDefaultSmsPackage(context));
} else {
intent = new Intent(Intent.ACTION_VIEW, smsUri);
}
intent.putExtra("sms_body", body);
return intent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment