Last active
May 1, 2021 15:31
-
-
Save Try64/6776c6e9a545f6cb04dda9d07f167421 to your computer and use it in GitHub Desktop.
JAVA Method to open SMS app with Data or Show Toast on Error for 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
public void openSMSClientWithData(@NotNull String phoneNumberWithCountryCode, | |
@NotNull String smsBody, | |
@NotNull Context contextForToastMessage) { | |
Uri smsUri = Uri.parse("smsto:" + phoneNumberWithCountryCode); | |
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri); | |
smsIntent.putExtra("sms_body", smsBody); | |
try { | |
startActivity(smsIntent); | |
} catch (Exception ex) { | |
Toast.makeText(contextForToastMessage, "Error! \n You do not have any SMS App", Toast.LENGTH_LONG).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment