Sending Mass Texts in Android - android

After users have logged into my app, I have an option to send a text to invite their friends (from mobile numbers) into the app. However, there does not appear to be a method of sending a mass text with potentially dozens of numbers without using a loop on the .sendTextMessage method.
What I have seen as typical:
protected void sendSMSMessage() {
Log.i("Send SMS", "");
String phoneNo = txtphoneNo.getText().toString();
String message = txtMessage.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
Is there another way to send mass texts without looping?

You are right but I would suggest using SEND ACTION as sending dozens of sms can cost user and there are application like what's app and hike, which can send or share text with friends at no extra cost.

You can only send one message at a time. If you do not like looping, maybe you can try recursion instead?

Related

Android code to send SMS with no errors but still not sending

Here the address stores current location of the device, which works. I get a toast that says SMS Sent but no sms is actually sent from the device. If the same code is used before finding the location, it works perfectly.
public void sendSMS()
{
String phoneNo = "+918110020302";
String message="Our Customer "+" has booked Cab no "+" using our application CabBooking and is cureently at location: "+address;
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
q.setText(message +phoneNo);
Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
If you haven't seen it yet, here is a working example: http://www.mkyong.com/android/how-to-send-sms-message-in-android/
It may depend on your network. If you are running this inside Android Studio's emulator, it may not work because it does not actually have cell service from within the emulator. You may need to be connected to a different network, or your cellular network.

How to send mutiple text messages from an android app?

Sorry if this question is already asked or seems stupid but i am stuck . I am writing an android application in which app sends different messages to different people the first one successfully send but there is a problem with the second one it doesn't show me error but it doesn't send the second message here is a portion of my code
public void sendSMSMessenger(){
Log.i("Send SMS", "");
try {
// SmsManager smsManager = SmsManager.getDefault();
SmsManager.getDefault().sendTextMessage(Emergencyphonenumber, null, "There is an emergency with your "+PatientRelationship+" "+Patientname+" please open the link to find the location "+"https://www.google.com/maps/place/"+latitude+","+longitude, null, null);
Toast.makeText(this, "Message Sent (Relative)", Toast.LENGTH_SHORT).show();
SmsManager.getDefault().sendTextMessage(Doctorphonenumber, null, "There is an emergency with your patient named "+Patientname+" please open the link to find the location "+"https://www.google.com/maps/place/"+latitude+","+longitude, null, null);
Toast.makeText(this, "Message Sent (Doctor)", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "Message Sending failed", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
Thank you....
You can not send messages simultaneously. In a way its hard for network to process all the messages collectively. Wait a little. Increase the time.

How to prevent Outgoing SMS from getting stored in KitKat?

I am creating an application that will send/receive messages to/from a certain gateway number. I don't want the messages that are sent to this particular number to be stored in the inbox of my device.
The code I am using to send the SMS is:
protected void sendMessage(String strMessage) {
try {
SmsManager smsMan = SmsManager.getDefault();
smsMan.sendTextMessage(gatewayNumber, null, strMessage, null, null);
Toast.makeText(getApplicationContext(),
"SMS was sent successfully!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS was not sent, please contact developer!",
Toast.LENGTH_LONG).show();
}
}
I have managed to tackle the problem of storing incoming messages by using the abortBroadcast(); function. (I realize this doesn't work above KitKat, and I'm fine with it).
But the messages that are sent from the application are being stored in the inbox too (only on KitKat), and that bothers me. Any solutions?

Android - Don't receive sms sent by sms manager

In my application I want to send an sms to a list of contacts. I used this code:
private void sendSMS(String phoneNumber, String message)
{
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
Toast.makeText(getActivity().getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
I didn't get any stacktraces, but I never received the message. Are there any formats for the phone number? Or is an emulator not able to send text messages? Any tips on how to actually receive the message are welcome!
Your given code seems correct but here are two quick recommendations:
Make sure you have added the permission to send SMS through your app. For that you need to add <uses-permission android:name="android.permission.SEND_SMS"/> in your app's manifest
You cannot send SMS through emulators as they do not have access to cellular network. For that you need to use an actual phone to test your code

Sending sms from android application

I have this code for sending sms to cellphones .
However it doesn't seem to deliver the sms, am i missing something ? should i buy some account from cellular companies ?
public void sending (View v)
{
String messageToSend = "this is a message";
String number = "1234567890";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, messageToSend, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!", Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
}
I have tried to send sms to my number many times,i used my number as "1234567890" using it as i dial it every day, then i tried using it with the international code "+9721234567890"
thanks in advance

Categories

Resources