Skip to content

Instantly share code, notes, and snippets.

@JMGama
Last active April 1, 2017 08:29
Show Gist options
  • Save JMGama/e93a81b19e8f5562b6221eee47795de9 to your computer and use it in GitHub Desktop.
Save JMGama/e93a81b19e8f5562b6221eee47795de9 to your computer and use it in GitHub Desktop.
Send SMS from an Android device
private void sendSMS() {
/*SEND SMS FROM AN ANDROID PHONE*/
checkSMSStatePermission();
String phone = "4455877998";
String text = "Hellow im sending this SMS from my app";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, text, null, null);
}
private void checkSMSStatePermission() {
int permissionCheck = ContextCompat.checkSelfPermission(
this, Manifest.permission.SEND_SMS);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.i("Message", "You do not have permission to send SMS!");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 225);
} else {
Log.i("Message", "You have permission to send SMS!");
}
}
@JMGama
Copy link
Author

JMGama commented Apr 1, 2017

This is how you can send a message from an android phone in your APK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment