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
Related
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.
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?
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?
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
I want to develop a project to send text messages in android using sendTextMessage() from android.telephony.SmsManager. When the message is sent a prompt appears. I want to know where can I find that code?
try below code:-
buttonSend.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, 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();
}
}
});
I believe you have not search it:
Question : Sending text messages programmatically in android already exists.
you can try this code also:
public void sendLongSMS() {
String phoneNumber = "0123456789";
String message = "Hello World! Now we are going to demonstrate " +
"how to send a message with more than 160 characters from your Android application.";
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
}
Code for Toast(prompt)
Toast.makeText(getContext(), "Your message",Toast.LENGTH_LONG).show();
Sms Manager
Toasts
Read this : What types of questions should I avoid asking? before asking question here.