Does not receive sms using SmsManager Android Studio - android

I am trying to send a message to my phone number whenever i click button in my apps. The apps say "message successfully send" but i did not get any sms. I am not sure whether its my phone number format or my smsmanager function is not correct. Here is my code. Any help would be appreciate. Thank you.
public void sendSmsByManager() {
try {
// Get the default instance of the SmsManager
SmsManager smsManager = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0);
//phone number format is Malaysia +60134567891
smsManager.sendTextMessage(phoneNumber.getText().toString(),
null,
smsBody.getText().toString(),
sentPI,
null);
Toast.makeText(getApplicationContext(), "Your sms has successfully sent!",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),"Your sms has failed...",
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}

Related

How to send sms from android app to mobile?

I have tried this code but I did not receive SMS in my phone.
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
//Get the SmsManager instance and call the sendTextMessage method to send message
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage("88xxxxxxx0", null, "hello javatpoint", pi,null);
You can send message from your application through this:
public void sendSMS(String MoNo, String msg) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(MoNo, null, msg, null, null);
Toast.makeText(getApplicationContext(), "Message Sent",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}
Also you need to give SEND_SMS permission in AndroidManifest.xml to send message
<uses-permission android:name="android.permission.SEND_SMS" />
Thanks. Happy Coding...

SmsManager displays alert prior to send SMS

I am really confused regarding one issue. Precisely, I'm sending a SMS to a number (fetched from web-service) each time application is opened. Code Snippet is as :
private void sendSMSToDevices() {
try {
String SENT = "SentSMSActivity";
String DELIVERED = "ReceivedSMSActivity";
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);
SmsManager smsManager = SmsManager.getDefault();
if (flagFirstTime) {
smsManager.sendTextMessage(phone_one, null, message_one, sentPI, deliveredPI);
} else {
smsManager.sendTextMessage(phone_two, null, message_two, sentPI, deliveredPI);
}
// Toast.makeText(getApplicationContext(), "SMS Sent!",
// Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
uses permissions in Manifest file are as ::
android.permission.SEND_SMS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
android.permission.RECEIVE_BOOT_COMPLETED
Each time I open the app, it dispays an alert prior to send SMS saying "(my_App_Name) would like to send a message to (phone_nember)"
I never put any alert inside my code. Why is it happening like this? Please Help.

Android send SMS with free sms plan

I have a very strange issue: my apps can send text message and many users reports they pay the sms even when their subscription can send sms for free. The sms is sended to a national phonenumber, a classic smartphone (a friend).
Here the code:
private void sendSMS(String phoneNumber, String message)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
MyLog.log("send message to " + phoneNumber + " string: " + message);
}
I asked my carrier (WIND ITALY) what the problem was, and they told me that it seems that the number was international and the sms plan do not cover the international sms.
The numbers that I've tried are all local, no one is international. Change a Carrier is not the solution ... i try this with all of the national carrier.
Someone out there have an advice ?

SMSManager not working on Samsung Galaxy S3 LTE

I created simple code to send SMS which is working on Xperia U and QMobile (local brand).
But it is not working on Samsung Galaxy S3 LTE
They code is
import android.telephony.SmsManager;
SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(activity, 0,new Intent(SENT), 0);
sms.sendTextMessage("01234567890", null, msg, sentPI, null);
first be sure to add the permission to send SMSs
<uses-permission android:name="android.permission.SEND_SMS" />
and then surround your code with try and catch to find the error that prevents sending in Samsung s3 lte ..
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("01234567890", null, msg, sentPI, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
You have missed to call PendingIntent deliveredPI
Try this code..!!
PendingIntent sentPI =PendingIntent.getBroadcast(activity, 0,new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0);
sms.sendTextMessage("01234567890", null, msg, sentPI, deliveredPI);
You can try using this library android-smsmms to send SMS
Settings sendSettings = new Settings();
sendSettings.setDeliveryReports(true);
sendSettings.setSplit(true);
Message mMessage = new Message(textToSend, addressToSendTo);.
sendTransaction.sendNewMessage(message, null)
Hope this helps you
EDIT
com.klinker.android.send_message.Settings sendSettings = new com.klinker.android.send_message.Settings();
sendSettings.setDeliveryReports(true);
sendSettings.setSplit(true);
sendSettings.setSplitCounter(true);
sendSettings.setStripUnicode(true);
com.klinker.android.send_message.Transaction sendTransaction = new com.klinker.android.send_message.Transaction(getApplicationContext(), sendSettings);
com.klinker.android.send_message.Message mMessage = new com.klinker.android.send_message.Message("Message", "9999999999");
sendTransaction.sendNewMessage(mMessage, 0);

Is it possible to send sms via coding without manually typing?

Hai i want to send the message via coding is it possible?
mobile number="xxx"
message="hai"
Anyboby kindly explain with code
//---sends an SMS message to another device---
private void sendSMS(String phoneNumber, String message)
{
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SMS.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
More Information: http://mobiforge.com/developing/story/sms-messaging-android
Here you go:
SmsManager sm = SmsManager.getDefault();
String number = "6508570720";
sm.sendTextMessage(number, null, "Test SMS Message", null, null);
Hope that helps!
REF: http://thinkandroid.wordpress.com/2010/01/08/sending-sms-from-application/

Categories

Resources