SmsManager with Email Address as Destination - NullPointerException - android

My cellphone carrier offers an sms-email gateway. This is done simply by entering the email address as the SMS message's destination. The email is delivered as 5555555555#mycarrier.com
I am attempting to use this with my new Android device. The standard android messaging application converts all messages with an email address as the destination to "MMS" and attempts to send them as data - not what I want to do.
Attempting with android.telephony.SmsManager:
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("address#example.com", null, "Message body here", null, null);
This throws the following exception:
Caused by: java.lang.NullPointerException
at com.android.internal.telephony.gsm.SmsMessage.getSubmitPduHead(SmsMessage.java:595)
at com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(SmsMessage.java:295)
at android.telephony.SmsMessage.getSubmitPdu(SmsMessage.java:599)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:228)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:107)
I've looked at this project, android-sms-email, which attempts to do the same thing. It also crashes in the same fashion when configured for my carrier.
This does not seem like the desired behaviour and I assume it is an Android bug (some bug reports hint at the issue). I've experimented a bit and can see that appending any number and some symbols to the email address do not cause the same failure but the message is not delivered either.
I've also tried using SmsManager.sendMultipartTextMessage but this runs into the same problem within SmsMessage.getSubmitPduHead.
Again:
SmsManager manager = SmsManager.getDefault();
// Works
manager.sendTextMessage("15555555555", null, "Message body here", null, null);
// Fails
manager.sendTextMessage("address#example.com", null, "Message body here", null, null);
Tested on an HTC Desire Z - Android v2.2

Please check this articles.
Programatically send SMS to email using Verizon Motorola Droid on Android
How to send SMS message reply to email address?
You should know the SMS gateway number of the carrier and make a message like this:
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("6425", null, "username#domain.com (Subject) message text", null, null);
Verizon wireless-> 6425, AT&T mobility -> 121 111

I've issued a bug report: http://code.google.com/p/android/issues/detail?id=16934

Related

sending SMS from server in Android Projects

I am making an Android App that takes food orders from customers for home delivery.
When the order is confirmed, I want the App to send an SMS to the Customer and the Hotel about the Order summary.
I am new to Android so pardon me for asking newb questions.
I tried Android's SMSManager to send the SMS.
public void sendthisSMS(String phoneNo, String msg) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
Toast.makeText(getApplicationContext(), "Message Sent",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}
This works great. But The problem is,Using this code, the SMS amount(0.5 Rs) is getting debited from the customer's Phone.
The App should send the SMS for free.I'm using a server for storing data of the App and its users.
How to implement this SMS thing on the server end so that The server bears the SMS fee and not the User using the App. ?
You are executing this method from your customer's phone. It is indeed logical to think that the balance gets reduced from the customer's phone. If you do not want to send the SMS from their phone, you have to use a SMS Gateway, such as this one. You have to pay for each SMS sent through this gateway.
So the net result is either you pay or your customer pays. If you are from a startup and want to minimize costs, I'd suggest you to include a disclaimer above your Order Now button stating that an SMS would be sent, and the customer will be charged for that.
The other option is to send an email to the 10 digit mobile number using this list, as #EliSadoff said in the comments.

send bulk sms on android sms app using api from another provider

I have a bulk sms site http://esmsafrica.com now I am building a sms app that will use the same API so that users registered on the site can still view there balance and send sms, I understand to use default smsmanager for android is below code, I have also searched on android developer page yet nothing seems to help, can someone let me know how to go about this, would I need to import any code from my site? I believe it should look like below code. I have a valid API code, username and password.
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, senderID, message, sentPI, deliveredPI);

How to send SMS from the Android app without making its record in device SMS view?

I want to send an SMS from my android app. But I don't want its record to be exist in device message view. I am currently using below code.
sendSMS(etsendernumber.getText().toString(), etmessagebody.getText().toString());
sendintent = new Intent(Intent.ACTION_VIEW);
sendintent.putExtra("sms_body","");
sendintent.setType("vnd.android-dir/mms-sms");
startActivity(sendintent);
But it is making sent sms record in message view of the device. Can we send a secret sms from android application?
Please advice.
Yes, the way you are trying to send SMS is by using the shipped messaging application. So it will always record the sent messages. You must use SmsManager to send the SMS.
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
In this way, your SMS wont be inserted into the list.
Also remember to add this in your manifest
<uses-permission android:name="android.permission.SEND_SMS" />
If you use android SMS application to send message then it would save that message in the outbox or sent. What you can do is delete that message from the sms database.
After sending sms Delete that message using this:
getContentResolver().delete(Uri.parse("content://sms/outbox"), "address = ? and body = ?", new String[] {etsendernumber.getText().toString(),etmessagebody.getText().toString()});
If msg is in out box
OR
getContentResolver().delete(Uri.parse("content://sms/sent"), "address = ? and body = ?", new String[] {etsendernumber.getText().toString(),etmessagebody.getText().toString()});
If message is in sent items.

Vcard sent as plain text

I have generated a vcard of the selected contact. I am sending it through sms (though i know we could send it through mms, but there are some phones that dont support mms).
when I am sending it to another phone, the exact string is received as such,
BEGIN:VCARD
VERSION:2.1
N:Mahajan;Sahil;;;
FN:Sahil Mahajan
TEL;HOME:964-695-7130
EMAIL;HOME:sahilmahajanmj#gmail.com
END:VCARD
But I want that on receiving this message, there should be a default option of saving it as contact.
I am sending it using the following code,
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(mobileNumber, null, vCardString, null, null);
here vCardString is the actual string containing the vcard. Let me know, if i need to post anything else.

Android: How to send SMS to email account

The stock Android text messaging app allows you to send SMS to an email account instead of a phone number. How is this done? I tried the following code and it failed.
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("myaccount#gmail.com", null, textMsg, sentPI, null);
This other question seems to be related How to send SMS message reply to email address?
... but the accepted answer says
Each cell carrier has a specific SMS number that you can send a text message to in a certain format. This is called a "SMS Gateway".
I want to send to my gmail account, not to AT&T.
Sorry, seems I misread the answer. Looks like my carrier (AT&T) will send the email for me. What puzzles me is how an app could work for different carriers?

Categories

Resources