Message not sent completely. Some text are missing - android

I'm trying to send a text message from my Android application. Everything works fine, but some of the text are missing. Here is my code:
String phoneNumber = "99********"; //Masked the number intentionally.
String message = "";
message += "This is Prabha, and thanks for using my application. ";
message += "Hope you enjoy this application. ";
message += "If you face any problem or issue, you can report the issue to our ";
message += "official mail id: pbha701#yahoo.com.";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
I am receiving the message, but it is not full. Some text are missing. I'm getting only the below text:
This is Prabha, and thanks for using my application. Hope you enjoy this application. If you face any problem or issue, you can report the issue to our officia
I've added the below permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.SEND_SMS" />
I am not able to find why the remaining text are truncated. Should I add any other permission or any setting changes required? Any ideas or help will be appreciated.
Thanks.

You need to use sendMultipartTextMessage() method available in SmsManager class.
sendTextMessage() method available in SmsManager class can send a text message of length 160 characters only.
To send multi-part SMS, divide the message using divideMessage() method available in SmsManager class. Then send this parts as an parameter in sendMultipartTextMessage(), as shown below:
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);

Related

Android. Use the SMS default interface to get the content in my app(to send it later). Delay SMS. It's possible?

I have a scenario in mind and I don't know if it's possible:
Open the SMS interface from my app.(I can make this part)
Use the interface to write the message and search the contact(s).
When send button is pressed I want to store the information in my app and send it later.(I don't know if this is possible, if it is please give me some help)
Sounds possible to me. You probably want the SMSManager to send a text... source
// Simplified...
String phoneNo = "8675309";
String sms = "Beni, I've got your number";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
} catch (Exception e) {
e.printStackTrace();
}
Regarding searching the contacts and sending the text at a later time, it would be helpful if you could provide more specifics.
How will your app search the contacts? Display a full list for them to pick from? Allow them to enter text to match against the contact's name?
When you say "Send it later", what are your constraints for later?
For example, you could simply bring up their phone's contact viewer, and let them choose...

SmsManager, send attachment in sms

How do I add an "attachment" into my SmsManager object when I'm trying tro send an sms?
My current function for sending a normal sms is:
public void send() {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(this.number, null, this.message, null, null);
}
I have looked a little bit at the sendDataMessage() but don't really understand it.. any help is appreciated.
Thanks.
EDIT
I don't want to use Intent for this. I have a List with Bitmap images that I want to send via an SMS/MMS. So I don't want to invoke the SMS app in my application. I want to send attachments "dynamically" depending on what's in my List.
SOLUTION
A friend of mine just posted me this link to a library: https://github.com/klinker41/android-smsmms
Message mMessage = new Message(textToSend, addressToSendTo);
mMessage.setImage(mBitmap); // not necessary for voice or sms messages
mMessage.setType(Message.TYPE_SMSMMS); // could also be Message.TYPE_VOICE
Haven't tried it yet, but it seems to be the real deal. Hope it's for good use for someone else too.
follow the code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
and add permission
<uses-permission android:name="android.permission.SEND_SMS" />

Sending sms in android

When I use the following code:
String phoneNumber="0527276513";
Uri uri = Uri.parse("smsto:" + phoneNumber.toString());
Intent smsSIntent = new Intent(Intent.ACTION_SENDTO, uri);
String smsBody="hii";
smsSIntent.putExtra("sms_body", smsBody.toString());
startActivity(smsSIntent);
The code opens the default application for sending SMS in my phone with the SMS body but the message doesn't get sent.
How do I send an SMS dynamically?
It is simple. Before making any changes please update your manifest by adding the following line:
<uses-permission android:name="android.permission.SEND_SMS"/>
And in your method/function use the following code:
String phoneNumber = "myphonenumber";
String message = "mymessage";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
Note that on Android 4.4 (KitKat) and higher devices, only the default SMS app can send text messages, per the blog post.
Assuming your app is not a full fledged SMS replacement app, the approach you have outlined is the correct one to ensure your app works on all Android versions.

Send my current location via SMS - Android

Im a new android developer.
I want to send a SMS which contains my current location. I know how to get my location coordinates. But what I want is send like a URL, and the User could open and see where I am(For example: With waze you can share you location and I think also with google maps app). I tried with google maps API but I didnt find like an option to generate a URL.
Can anybody give some ideas?Or an API?
Thanks everyone!!!
I guess this is what you need.
public void sendLocationSMS(String phoneNumber, Location currentLocation) {
SmsManager smsManager = SmsManager.getDefault();
StringBuffer smsBody = new StringBuffer();
smsBody.append("http://maps.google.com?q=");
smsBody.append(currentLocation.getLatitude());
smsBody.append(",");
smsBody.append(currentLocation.getLongitude());
smsManager.sendTextMessage(phoneNumber, null, smsBody.toString(), null, null);
}
I would use a map overlay instead of default maps.
I have developed an app which uses the location feature and shows in map. See it on google play.
"Wherez U" https://play.google.com/store/apps/details?id=com.kabhos.android.apps.knowmylocation
String uri = "http://maps.google.com/maps?saddr=" + currentLocation.getLatitude()+","+currentLocation.getLongitude();
SmsManager smsManager = SmsManager.getDefault();
StringBuffer smsBody = new StringBuffer();
smsBody.append(Uri.parse(uri)); `
smsManager.sendTextMessage(phonenumber, null, smsBody.toString(), null, null);
you have to parse that string to uri. it worked for me
refer this link
http://javapapers.com/android/get-current-location-in-android/
after getting it send that location using sms api .
I was also facing the same issue and was not able to generate URL to be send to the receiver and I found this. Here I have a link in which we have to pass the LAT and LONG of the current location of sender and then you have to just send this link to your receiver.
https://www.google.com/maps/preview/#(latitude),(longitude),(zoom level)z
https://www.google.com/maps/preview/#-15.623037,18.388672,8z
You can also try first to open this link in your browser and then apply it to your project

In Android Where is sms outgoing saved if that sms sended by class SmsManager, not application messager default

I want read information of sms outgoing that sended by class SmsManager in Android not by default application messenger in device. Any idea for help me? Many thank all of you!
Nothing is saved by SmsManager. The messages are sent to their recipient over the mobile network, and that is it.
Individual apps may save messages that they also send via SmsManager. The details of which apps save what would depend upon the apps.
Please follow the following two steps:
1. Send your message
2. Insert the message to "sent" messages box
SmsManager smsManager = SmsManager.getDefault();
String address = "address here";
String text = "text message here";
// Send you message
smsManager.sendTextMessage(address, null, text, null, null);
Uri uri = Uri.parse("content://sms/sent/");
ContentValues values = new ContentValues();
values.put("address", address);
values.put("body", text);
// Insert the message to "sent" messages box
getContentResolver().insert(uri, values);
PS: You can check the complete code here

Categories

Resources