My mobile app occasionally is sending text messages, everything works great on most phones but i am starting to receive emails from some users stating the messages aren't going out. Here is the code i am using:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+12223334444", null, "test sms", null, null);
I've read somewhere that I should use the PendingIntent, so i tried it as follows:
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, message, sentPI, deliveredPI);
So far I have gotten emails from users of Samsung Galaxy S II, Sprint Evo Shift, Samsung Sidekick phones.
Please keep in mind it's not phone specific, i have tested the app on two of these phones (my friends) and the text message was sent normally
The problem here is that you aren't handling retries at all. It is possible for the SMS to fail to send in a variety of colourful ways. You can listen for these events using the sent PendingIntent using something like:
public void onReceive(Context context, Intent intent) {
if (getResultCode() != Activity.RESULT_OK) {
// failed to send the sms, see SmsManager.ERROR_<description> for more info on why
}
}
What I suspect is happening is that users have no signal at the time you send the message, so it fails and never retries. This would also explain why it isn't device specific.
Related
I am working on an application which is sending text and image messages. I am sending Text and Image using SmsManager in my Application as below. The problem is, this is sending separate messages for every image and text I am sending thus not getting in exact order, but I want to send and get message in exact order.
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
NewLeaveItemActivity.this, 0, new Intent(ACTION_MMS_SENT), 0);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
mainImageContentUri, null, null,
pendingIntent);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
qRCodeContentUri, null, null,
pendingIntent);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
storeContentUri, null, null,
pendingIntent);
PendingIntent intent = PendingIntent.getBroadcast(
NewLeaveItemActivity.this, 0, new Intent(ACTION_MMS_RECEIVED), 0);
SmsManager.getDefault().sendTextMessage(mEditMobileNew.getText().toString().trim(), null, bellowMessage, pendingIntent, intent);
It wouldn't be a professional or better way to split the MMS into 2 or 3 parts and send them separately. There would be a better way so that we can control what order they are received in?
Please help me.
use this amazing library to send media through sms
https://github.com/klinker41/android-smsmms
Create one large mms message. Convert all sms into mms too.
Api will automatically divide into multiple mms and will be in order.
Don't use SMS all messages should be part of a big mms.
method used here
divideMessage
Added in API level 4
public ArrayList<String> divideMessage (String text)
Divide a message text into several fragments, none bigger than the maximum SMS message size
.
sendMultipartTextMessage
Added in API level 4
public void sendMultipartTextMessage (String destinationAddress,
String scAddress,
ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents,
ArrayList<PendingIntent> deliveryIntents)
Send a multi-part text based SMS. The callee should have already divided the message into correctly sized parts by calling divideMessage.
I'm developing a business application. When user register in app, app will send his coordinates by using active internet connection. But if connection is not avaliable coordinates will be sended by sms.
Using SmsManager in app to send sms:
sendSMSButton.Click += (s, e) =>
{
var phone = "999999";
var message = UserLocation;
var piSent = PendingIntent.GetBroadcast(this, 0, new Intent("SMS_SENT"), 0);
var piDelivered = PendingIntent.GetBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);
_smsManager.SendTextMessage(phone, null, message, piSent, piDelivered);
};
My problem is that the message that was sent is displayed in user's phone, and he can see coordinates and phone number. So he can edit this data and send again.
How I can prevent showing messages that was sent by smsmanager in outgoing sms of user's phone ?
Doesn't seem like you can, sendTextMessageWithoutPersisting has only been added in API 28 and is intended for internal carrier use only. You won't be able to use it since this method requires the Manifest.permission.MODIFY_PHONE_STATE permission. You can read more here in the docs.
In Android there are AlamManager:
AlarmManager alarmanager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmanager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+(i*1000),pendingIntent);
and SmsManager:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(senderNumber, null, "Sorry, I'm kind of busy right now, call u l8r.", null, null);
and so on. I would like to manage calls? Is there also something like 'CallManager'?
You're probably looking for TelephonyManager
my app need's to send data to another android device so far its sending it through sms messages that gets blocked in the other android device ... but since the kitkat version i cant block them anymore.. is there anyway of sending push messages in the background to another user and receiving them back ? and if so... I would love to see any example ( I don't prefer GCM i think its way too complicated.. ) .
this is the code i am using to send the SMS message :
SmsManager sm = SmsManager.getDefault();
ArrayList<String> parts =sm.divideMessage(String.valueOf(points));
int numParts = parts.size();
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < numParts; i++) {
sentIntents.add(PendingIntent.getBroadcast(getBaseContext(), 0, getIntent(), 0));
// deliveryIntents.add(PendingIntent.getBroadcast(getBaseContext(), 0, data, 0));
}
sm.sendMultipartTextMessage(number,null, parts, sentIntents, deliveryIntents);
SmsManager.getDefault().sendTextMessage(number, null, String.valueOf(points), null, null);
}
Looking for something similar just for the push messages.
You could send a data SMS. They operate differently than a regular SMS because they use a port upon sending, and so you specify that same port on the receivers handset. This avoids the problem of competing intent filter priority on the SMS receiver.
This allows direct sending from one android to another.
See here for an example
Google Cloud Messaging is what your are after:
http://developer.android.com/google/gcm/index.html
One disadvantage over your current method is that you will probably need a server to act as a broker, as a GCM message can only have a relatively small payload
I tried sms activity using this link
but the problem is that it always gives "message sent"
how to know if the message is really sent!
here is code
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
//...
}
In the mentioned link, there is no PendingIntent set for deliveryIntent or sentIntent in order to receive the status of message you need to send PendingIntent. See this link
I also faced similar NPE scenario but problem at my end was due to wrong phone number.
So you must also check if phone number was correct or not.