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.
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.
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 am sending an SMS to multiple numbers. When I choose only one, it works, and the message is being sent immediately. But when I use multiple (3 for example) SMS Intent is opened, but after I click Send button I see "Sending..." message all the time, SMS is not sent.
Intent sms = new Intent(Intent.ACTION_VIEW);
sms.setType("vnd.android-dir/mms-sms");
sms.putExtra("address", getSMSNumbers);
sms.putExtra("sms_body", "Help!!!");
startActivity(sms);
And getSMSNumbers String looks like this: 512991220;505202222;606123456.
What is wrong? Why isn't the message being sent and it's "sending" all the time?
Also I see when I have more than 1 number, it's being converted to MMS - why?
Maybe you could loop through the numbers and send messages one by one, like this
android.telephony.SmsManager.getDefault().
sendTextMessage("00112233", null, "Message body text", null, null);
I managed to do this - needed to turn off "Group Messaging" in AVD Settings. App was trying to send MMS and that's why it wasn't being sent.
Using this code, i am able to send a notification to my own device.
Intent intent = new Intent(getApplicationContext(), ContactDonor.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
//display text
String body = "Please Click on this to accept!";
String title = bloodgroup+" Required";
Notification n = new Notification(R.drawable.ic_launcher, body , System.currentTimeMillis());
n.setLatestEventInfo(getApplicationContext(), title, body, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
finish();
But now i have a screen where a person's details are displayed like:
Name: ...
email: ...
, and there is a message box and a Request Button , on the click of that button, he should receive a notification with that particular message. How can this particular thing be done?
It cannot be implemented by using PUSH notifications. PUSH notification is useful when there is server-client comm is implemented where server notifies the client about the event that has occurred on server side.
What you are trying to implement indirectly is server-client architecture, where your device will act as server. If you mould your current architecture to server-client you will be able to send notification to other device. In this case also, you don't need PUSH notifications, it will be a simple server-client communication.
For more info on PUSH please see: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html#c2dm_sendmessage
You can also send SMS, but that will not solve your problem. According to me, there is no other solution that you can apply to send notification.
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.