public static Intent newSmsIntent ( Context context , String body , String [ ] phoneNumbers ) { Uri smsUri ; if ( phoneNumbers == null || phoneNumbers . length == 0 ) { smsUri = Uri . parse ( "smsto:" ) ; } else { smsUri = Uri . parse ( "smsto:" + Uri . encode ( TextUtils . join ( "," , phoneNumbers ) ) ) ; } 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 ) ; } if ( body != null ) { intent . putExtra ( "sms_body" , body ) ; } return intent ; }
Creates an intent that will allow to send an SMS to a phone number