Reputation: 7358
I have created an android application. Now I want to send SMS through it to a real mobile number... Can somebody please help me with it. The information provided on the internet is to send message between two emulators. But I want to send sms on a real mobile number... Please help me out with it.
Upvotes: 1
Views: 1867
Reputation: 10079
I think you couldn't send SMS from Emulator to real device because it doesn't have any number. I have added the code below which will be helpful to send sms from real device.
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, RoadMoveActivity.class), 0);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sms_phonenumber, null, sms_message, pi, null);
Its worked for me
Upvotes: 1
Reputation: 3444
The emulator its not a real phone, don't have a number or sim card so it can't send or receive sms from external devices. From cmd telnet you can use sms send phonenumber
EDIT :
private SmsMessage[] getMessagesFromIntent(Intent intent) {
SmsMessage msgs[] = null;
Bundle bundle = intent.getExtras();
try {
Object pdus[] = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int n = 0; n < pdus.length; n++) {
byte[] byteData = (byte[]) pdus[n];
msgs[n] = SmsMessage.createFromPdu(byteData);
}
}
catch (Exception e) {
Logger.getDefault().error("Fail to create an incoming SMS from pdus", e);
}
return msgs;
}
Upvotes: 1
Reputation: 12134
Refer this Question for how to set up an email account in your android emulator How can i configure gmail in Android emulator? and then use the following code to send a email,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
Upvotes: 0