Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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