You need SEND_SMS permission:
Code:
try {
SmsManager smsManager = SmsManager.getDefault();
String sPhoneNumber = "1-222-3333";
String sMessage = "Hello World";
smsManager.sendTextMessage(sPhoneNumber, null, sMessage, null, null);
Toast.makeText(this, "Message has been sent", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, "Message send failed", Toast.LENGTH_LONG).show();
}
Warning: Make sure your app doesn't send SMS without user's knowledge. It will violate the Google's policy and your app will be suspended.
- Do not send SMS, email, or other messages on behalf of the user without providing the user with the ability to confirm content and intended recipient.
No comments:
Post a Comment