Using the native sms app to send an sms without launching itself - android

I want to send an SMS, but not using the SmsManager class. I want to do it with the native SMS app which is there on an Android phone.
And here is the twist : I do NOT want to launch the native app while doing it. Is there some format of intent which can send an sms directly (given the sms-body and the phone number to send it to) via the native app (without the user having to click 'send').
I googled the same, but all results and responses simply launched the native sms, waiting for user to manually send the SMS. I have seen this being implemented in some apps like 'MightyText' and wish to implement in my app as well.
Please help !

Using the SmsManager will send the sms through the system but will not put it in the SMS content provider as was mentioned earlier. Hence any native messaging app will not see it.
To do so, you have to add it manually via the SMS content provider AFTER you send the message normally via SmsManager. Here's some sample code to help:
ContentValues values = new ContentValues();
values.put("address", "+12345678"); // phone number to send
values.put("date", System.currentTimeMillis()+"");
values.put("read", "1"); // if you want to mark is as unread set to 0
values.put("type", "2"); // 2 means sent message
values.put("body", "This is my message!");
Uri uri = Uri.parse("content://sms/");
Uri rowUri = context.getContentResolver().insert(uri,values);
And that's all. After that you'll notice that it's added and the native messaging app displays it normally.
Please click "accept" answer if it works out for you.

Ok, so you want to send a SMS, without using SmsManager and plus it should show up in your native SMS app list?
Firstly, you cannot send SMS bypassing SmsManager. If you look at the source code of all native messaging app for Samsung Galaxy Nexus, it will invoke SmsManager on button click.
so, the below piece of code as posted above is correct
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
Secondly, after sending the message, native apps put it into into SMS ContentProvider
follow this How to save SMS to inbox in android?
Word of caution is that now adding to this is not supported. So you may have to resort to a hack to add it into the sent box.

If you only have ACTION_SENDTO, then, of course, any application that can send will pop up.
You need to add a filter for SMS
with URL. See https://stackoverflow.com/a/2372665/94363
or with content type https://stackoverflow.com/a/10613013/94363

I have done something similar in a project I was working on. You need to use SmsManager
It would be something like this -
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
You can use this to send an SMS programatically.

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

Related

If I create an Android app that sends texts, will the text show up in the default messaging app?

I would like to enable my users to send custom texts from within my app. These messages would be sent using their carrier via SMS. I've never done this before, but it looks like I should use the SmsManager Class provided in the Android API.
Is there a way to send the text without it displaying in their default text messaging app (i.e. Hangouts, Messenger etc.)? If that's possible, what happens when someone replies to the message that my app sent?
Yes, you can send SMS using the SmsManager, and You can try below 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();
}
}
Also you need to give SEND_SMS permission in AndroidManifest.xml to send message
<uses-permission android:name="android.permission.SEND_SMS" />
In case if your message text is more than 160 char.then you may change your code as below:
ArrayList<String> parts = smsManager.divideMessage(msg);
smsManager.sendMultipartTextMessage(phoneNo, null, parts, null, null);
You have to use SmsManagerclass to send text message.
firstly you have to get a instance of this class
SmsManager manager= SmsManager.getDefault();
then pass phone number and text message to sendTextmessage()
manager.sendTextMessage(phoneNo,null,textMessage,null,null);
You need to provide user permission also
<uses-permission android:name="android.permission.SEND_SMS" />
Yes it will show up.
After android KitKat version, it is not possible to avoid writing sms to sms provider.
After 4.4+ the default SMS app takes care of writing the sent messages to the sms provider. Also only the default messaging app have the permission to delete sms.

Sending SMS without Intent on android issue

I'm trying to send SMS in the background of android phone . I'm using this code along with the manifiest permessions :
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
sendSMS(number, text);
Now the issue I have is when I try to send for a regular number (05239652203) for example it works perfetly , but when I try to send for a short number (5555) for example a pop up shows and says "This is application is trying to send SMS message click Confirm or cancel" something like that . Due to the nature of my application It requires sending the SMS in the background (I'm trying to develop an application that helps the phone owener to trace the phone if it was stolen) . So is there's any way to turn around this issue ?? and thanks in advance

how to send image to a contact number in android

I am able to send normal message to a number through SmsManager. But I want to send image(mms) along with text message. I know it can be sent through Intent with ACTION_SEND, but I am using SmsManager. But searching about it, some sources say it might not be possible. But has someone made it possible?
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);

detect the application that sent sms in android

I'm new to android Develpoment
my first application is ant-spy
I try to detect the application that sent sms (that is listening to send an sms )
I ask you to help me this application and if possible give me a source code for DECT application waiting to send sms or a code that resemble.
Thanks.
This code is used to send sms:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(smsNumberToSend, null, smsTextToSend, null, null);

How can I see in SMS app my messages sent from within my app?

I have just created a cool app that work with SMS.
You have just to send some SMS to your phone and it reply with location and some handy stuff. Usefull for my frieds, I just told them send me a SMS with "WhereIs" and I will automatically reply you with my position
For the response, I use:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, position, pi, null);
And that is very fine.
Unfortunately, all sent SMS does not appear in my SMS application, so I don't know that a SMS has been send.
I really would like to know what the people asking me are receiving as answer.
So, to create a correct question:
Is there a way to "tell" the SMS app that I sent some sms in my application?
Thank a lot for any answer.
Just an information: You should always use the SMSManager from the "android.telephony"-package, because the one from the "android.telephony.gsm"-package is deprecated.
To your Question: You can check if the message was successfully send by using the "Activity.RESULT_OK"-global in the Activity you specified with the Intent "pi". See here.
You would want to add that message to Android's built in "Sent folder" aka "content://sms/sent". I have not tried it but I guess it should work. Cause if I am not wrong all the messages app would get your sent messages from this location. Give it a try. Please check as answer if this works.
ContentValues values = new ContentValues();
values.put("address", incomingNumber);
//values.put("date",(String)s);
values.put("protocol", "0");
values.put("read", "1");
values.put("status", "-1");
values.put("type", "1");
values.put("body", selectedText);
ContentResolver contentResolver = getContentResolver();
Uri newUri=contentResolver.insert(Uri.parse("content://sms"), values);
but the prblm is tht its showing as the inbox message that is sent by the incomingNumber...not as the sent items....

Categories

Resources