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
Related
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)
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 trying to send an sms text message with my android application, however i am receiving nothing when i run it
here is the code
int minSms = 100001;
int maxSms = 999998;
Random rSms = new Random();
int iSms = rSms.nextInt(maxSms - minSms +1) + minSms;
try {
SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(getActivity(), 0,new Intent(SENT), 0);
sms.sendTextMessage(mobileNumber, null, Integer.toString(iSms), sentPI, null);
Toast.makeText(getActivity(), "SMS sent.",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getActivity(),
"SMS failed, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
I am testing with my own mobile number which i am not going to share but it is in the format 07789123456
Do i need to add any area codes with it, or should it work with the straight 11 digit number?
Please take a look at SMS Manager send mutlipart message when there is less than 160 characters . Im pretty sure the text you want to send is to long. Depending on the alphabet (i.e. including emojis) you are using, the message is limited to 70 characters. You have to split the message into a multipart message:
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(longMessage);
sms.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
I am developing an application which needs to send SMS.
I am using SmsManager.SendTextMessage and SmsManager.sendMultipartTextMessage , Both of them are working well , the main problem is sent message will be saved on sent items(only in Kitkat , the older version don't save SMS) , but I don't need to save message.
My app is default messageing app.
What should I do to prevent saving SMS in kitkat?
Here is my code:
try
{
SmsManager smsManager = SmsManager.getDefault();
String body ="Test";
String to = "5556";
ArrayList<String> parts =smsManager.divideMessage(body);
smsManager.sendMultipartTextMessage(to,null, parts, null, null);
}
catch(Exception ex)
{
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
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.