The code for the prompt after using sendTextMessage - android

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.

Related

how to send sms automatically in android

i am using this code to send sms automatically but is not working ,i am able to send sms by using intent
SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0);
sms.sendTextMessage("+91"+"**********", null, "hii param", sentPI, null);
Toast.makeText(getApplicationContext(), "Your sms sent check your inbox",Toast.LENGTH_LONG).show();
Use Permissions in your Android.manifest file like this
<uses-permission android:name="android.permission.SEND_SMS"/>
And then invoke the SmsManager i.e
SmsManager managerForSms = SmsManager.getDefault();
managerForSms.sendTextMessage("Your text message");
Or you may refer to this Stack's question How to send sms in Android. (See accepted Answer)
Try this code,
public void sendSMS(String phoneNo, String msg){
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
And use this permission in your manifest file
<uses-permission android:name="android.permission.SEND_SMS" />
Update:
Add your country code before pass the phone number
String phoneNo="+91"+editText.getText().toString();
Update 2:
Another possible cause for not working
If u are testing this code in dual sim phone then sim slot 1 always keep active otherwise it " no service" error.
reference - https://stackoverflow.com/a/32090923/3879847
Code Which works for me is this.. Before you need to provide permission in manifest and also need to ask during runtime
<uses-permission android:name="android.permission.SEND_SMS" />
and in Activity
runOnUiThread(new Runnable() {
#Override
public void run() {
String number = SMSEditText.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, Message, null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
also if message lenght is greater than 140 or something.. you need to split the message otherwise. it wont work .. which can be acheived by mulitpart text message

Send SMS for Missed Calls only once Android Eclipse

i want to send a sms once. if already sent i want to skip the code or somthing.
Log.i("Send SMS", "");
String phoneNo = incomingNumber;
String newN = incomingNumber;
if (newN!=oldN)
{
SmsManager smsManager = SmsManager.getDefault();
String message = "im on a meeting call you later -ExAutoSmS-";
try {
smsManager.sendTextMessage(phoneNo, null, message, null, null);
oldN = incomingNumber;
} catch (Exception e) {
e.printStackTrace();
}
}
# RAJITHA first create shared preferences then check every time before sending an sms if there is no number exist in shared preference..
But remember shared preference store number till you didn't clear or delete the app.. so after finish your task clear the saved no from preferences..
Hope you helped..enter link description here

How to send SMS in languages other than english using SmsManager?

I have tried to send Text Message using SmsManager in android. Message is delivering fine. When i tried to send message in different language it delivers as ??????. I don't know what's the problem.
try {
SmsManager smsManager = SmsManager.getDefault();
String phno = "+919715361062";
String msg = "டெஸ்டிங்";
smsManager.sendTextMessage(phno, null, msg, null, null);
}catch (Exception e){
e.printStackTrace();
Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_LONG).show();
}
try this :
ArrayList<String> arrSMS = smsManager.divideMessage("Text to send");
smsManager.sendMultipartTextMessage("Number", null, arrSMS, null, null);
You have to use sendMultipartTextMessage().
Look at this question: Android: Unicode/Charset problems when sending an SMS (sendTextMessage)

Sending Mass Texts in 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?

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