Android send SMS with free sms plan - android

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 ?

Related

Does not receive sms using SmsManager Android Studio

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();
}
}

Android sendTextMessage not working for second account even if SEND_SMS permission is granted

I am trying to write a Sms app.
When I use
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, body, null, null);
to send sms, the app works fine on the main account, but it always fail to send sms when I switch to the second account.
I already give the second account permission to send sms in Settings, and also add
<uses-permission android:name="android.permission.SEND_SMS" />
in Manifest.xml
Also, since the target sdk version is 23, I also request permission during the run time. However, it is still not working after all permissions are granted. T_T
It will not crash, it just does nothing. Therefore, I think it is an issue related to permission, I just don't know where the problem is.
Anyone one help?
UPDATE:
public void sendSMS(Context context, String phoneNumber, String messageBody)
{
Intent sentIntent = new Intent("SENT");
sentIntent.putExtra("phone_number", phoneNumber);
sentIntent.putExtra("message_body", messageBody);
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, sentIntent, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("DELIVERED"), 0);
/**Catch the sms send fail to check wether cause by permission deny**/
try{
Log.d("Debug phoneNumber", phoneNumber );
Log.d("Debug messageBody", messageBody);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, messageBody, sentPI, deliveredPI);
}
catch (Exception e)
{
e.printStackTrace();
}
}
The two Log.d() methods can work, but smsManager.sendTextMessage() does nothing if switch to the secondary account.

sendMultipartTextMessage and monitor send and received

i have read multiple threads on how to send and receive multipart messages. I have implemented the following code and it works!
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(SMSBroadcastReceiver1, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(SMSBroadcastReceiver2, new IntentFilter(DELIVERED));
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(smsToSend);
ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>();
for (int i = 0; i < parts.size(); i++) {
sentList.add(sentPI);
deliveredList.add(deliveredPI);
}
//smsManager.sendTextMessage(phoneNumber, null, smsToSend, sentPI, deliveredPI);
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, sentList, deliveredList);
and i have one registered SMSBroadcastReceiver2 and SMSBroadcastReceiver1.
The thing that worries me is:
I have one single PendingIntent sentPi and deliveredPi, that are registered with SMSBroadcastReceiver1 and SMSBroadcastReceiver2.
And then i put them in ArrayList's multiple times, depending on how long is the message.
Is this a good thing? Or should i have different Intents and Receivers
for each part of the message.
Also when do receivers fire in my code? I have noticed it only fires once when the message is sent and once when its received(i coded them to display Toast Messages at those moments), no mater how long the message is. Is it when the first part is delivered or last...?

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/

How can I send sms with contacts?

I am new to android . In my application I want to send sms with contacts. How can i send sms to other through my appplication
private String SENT = "SENT";
private String DELIVERED = "DELIVERED";
...
PendingIntent sentPI = PendingIntent.getBroadcast(this.context, this.getUniqueId(), new Intent(this.SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this.context, this.getUniqueId(), new Intent(this.DELIVERED), 0);
String smsNumber = "+123456";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(smsNumber, null, "sms content", this.sentPI, this.deliveredPI);

Categories

Resources