Created
July 13, 2015 17:36
-
-
Save almozavr/fc76f605c03822a3ee14 to your computer and use it in GitHub Desktop.
Sms intent builder
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
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