Last active
August 29, 2015 14:08
-
-
Save tckb/1f21dbfc4ddab1975b87 to your computer and use it in GitHub Desktop.
Code snippet to pop up the default sms client on Android
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
private void sendSMS(){ | |
Intent smsIntent; | |
// Check the version of the android | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) | |
{ | |
// Get default sms package, if exists | |
String smsPackage = Telephony.Sms.getDefaultSmsPackage(this); | |
smsIntent = new Intent(Intent.ACTION_SEND); | |
smsIntent.setType("text/plain"); | |
smsIntent.putExtra(Intent.EXTRA_TEXT, "moxtra_url_link"); | |
// Check if user has a default smsclient | |
if (smsPackage != null) | |
{ | |
smsIntent.setPackage(smsPackage); | |
} | |
// else user will be prompted to choose a smsclient of his favorite | |
} | |
// the legacy code for sending the sms | |
else | |
{ | |
smsIntent = new Intent(Intent.ACTION_VIEW); | |
smsIntent.setType("vnd.android-dir/mms-sms"); | |
smsIntent.putExtra("sms_body", "moxtra_url_link"); | |
} | |
startActivity(smsIntent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment