I'm looking for some quick feedback on developing an in-app SMS validation solution as part of my registration process for an Android app. The guy on my team working on the issue seems to be having trouble.
Disclaimer: I am not a developer myself, just have basic coding knowledge.
Basically what should happen is this:
User enters phone number
User selects a "validate number by SMS" button
SMS compose window is launched. Message field is pre-populated with
a validation code. Recipient number pre-populated with a Twilio
phone number connected to my server
Once the user hits send, the SMS window should automatically close
once the message is successfully sent, returning them to my app's
registration process where it will be either waiting to receive a
response from the server or checking at intervals to see if it has
permission (i.e. the phone number was verified) to move to the next
phase of registration.
The problem is with step #4, as my developer has indicated that he doesn't have an object tied to the messaging app, so he is unable to call functions on it... This is where my coding knowledge falls short, so I'd like to hear how others have (or would have) solved this problem. I'm sure that it is solvable.
Thanks!
dont use the text message app intent and just send it within your app
PendingIntent pi = PendingIntent.getActivity(ccc, 0, new Intent(), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
I've run into the same issue. You should be able to do what you want with code like this (copied from link below):
private void launchSMSActivity(final CharSequence phoneNumber) {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.fromParts("sms", phoneNumber.toString(), null));
smsIntent.putExtra("sms_body", mMessageWithPattern);
smsIntent.putExtra("exit_on_sent", true);
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(smsIntent, SEND_SMS);
}
However, there is apparently a bug in 4.3 that causes the message field to appear blank. Hitting send will still send the message. The bug is here: https://code.google.com/p/android/issues/detail?id=58153
Given that, your may choose to send from within the app per tyczj's answer, though keep in mind that doing so will require adding an SMS permission to your app. When users get the permission confirmation dialog it will appear at the top with a notice that it may cost them money. A number of malicious apps have used this permission to run up users' phone bills so many users look at it with suspicion.
You may also choose to only send SMS from within the app on 4.3 devices and use the code above to do it the way you want on all other devices. That doesn't solve the permission problem, unless you publish two APKs - one for pre 4.3 devices without the permission, and one for 4.3 with the permission. This last option is what I'm now considering for my own app.
Related
I can successfully send an SMS using the following code:
public static void SendSMS(String message, String number) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number, null, message, null, null);
}
However, the message appears in the conversation between me and the person I send it to. Due to the nature of the game I am creating, each player receives a "secret message". I don't want the person running my app to know others' "secret message" by checking the Messaging app.
Is there any way to prevent this behavior? The only way I can think of is by deleting the most recent message in the conversation, but I'm not sure how to do that either, and there's probably an easier way.
Edit for clarity: For my game, only one person is running the app. I am broadcasting a "secret message" to each player in the game. The person running the app should not know what those messages are, so they should not appear in the user's Messaging app.
I have written an answer about sending SMS messages here: Send SMS until it is successful
The sender of the message will not see the message anywhere unless it is explicitly displayed by the app that is running the code somwhow. Atleast that is my experience and I have used it for various occasions.
Though I must admit that I am not sure if that is the case for Android 4.4 as I believe they made some changes regarding SMS handling.
From this site: http://thepu.sh/trends/android-kitkat-far-reaching-update-puts-sms-app-developers-notice/
There can only be one default SMS app at any time
If an app is not chosen as the default SMS app, Google wants the developer to disable the option for that app to send a message. If not disabled, any message sent through this non-default app will not be visible in the user’s default SMS app.`
In Android 4.4, My App is not an SMS App but it need to send SMS(multiple times).
The thing is that the Sent SMS will be stored in Default SMS App(Hangouts).
It would spam/annoy users a lots. I would like the SMS actions are transparent/silently with End-Users.
AFAIK, we may prevent this by setting my App at the moment I send the SMS & change back later.
But this is not really an option since end-user flow become complicated & may lead to confusion. another reason is Default SMS App may lose the System Broadcast when my App was set as Default SMS App.
Is there complete solution on this?
Thank you for you support.
If i am not wrong.. you want to send sms without storing in default sentitems list..????
The task you mentioning is possible without any confusion in the flow...
This can be done by setting the sentIndent in smsmanager to null.
public final void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
This will suppress the sentintent thereby avoiding to store in the default sent items...
There is also a previously discussed question regarding this topic in stackoverflow..
How to send SMS from the Android app without making its record in device SMS view?
Check it out...
If you could share the code u use for sending message.. It would be more easy to help for others...
I've got an idea for an Android Application, however I am unsure if it would work. Essentially what I want to do is "intercept" all text messages sent from any SMS App and make modifications to them.
For example, say I write out the following SMS:
Hi {Name}, how are you today? Can you tell {Boss} I'll be 15 minutes late today.
The onSMSSend function in my application(assuming it is currently running in the background) would then be able to edit the content of the message(Eg. Replacing variables with ones defined in the application), and then send it on to the recipient.
Is Android able to provide this functionality?
No it is not. Android may be able to inform you after an SMS was send. But there is no way to intercept a message that should be sent and apply changes to it on a non rooted phone.
What you could do is to write a new messaging App that allows the user to type a message, choose a number and send the message. Now you have full control over the message that is send but building a replacement for the sms app is a fair amount of work.
in my app i need to be able to send a text message in a background, without users intervention. I am using SmsManager (code below) to accomplish that. It does send a message but the popup asking me to choose a delivery method still shows up (even after the message is sent). I do have Google Voice installed thus the popup. Is there a way for me to avoid displaying this popup while sending text message? Perhaps i shall use a different method?
Thanks!
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, message, null, null);
Update: so just to see what will happen i selected a default delivery method being "text message" and check the box saying use this as default. Now when i send the message using the code above it sends it in the background but it also bring up the empty form to send a message to :| How do i get rid of this? :)
restored the device and problem was gone, so must've been a third party app causing the send new message form, its all good now, sms is being send in a background. thanks for your help all...
I tested that and didn't have that problem. I have Google Voice installed but only use it for voicemail on my main line so maybe thats it. Can I assume you have a separate Voice number? I think this is just an issue of Android not knowing which number to send the text from so you will have to pick a default the first time. Is there the option to set it as the default method? If your intention is the send this text secretly then maybe you might want to rethink your intentions for doing so.
I m working on application in which i have to send all contacts from Android mobile to other mobile through SMS. I don't have any problem in getting contact information but when I send those Contacts after few messages there is Alert Window pop up saying "A large number of message have being send" and ask if you want to send or not.
I am testing this application on HTC Hero.
Is this problem is for specific mobiles or for all?
I don't know what should i do to avoid this window because I cant get SMS Sent event.
Please help me with any ideas that i can implement........
The alert window doesn't appear after a "few messages" — the limit is 100 messages, per application, per hour, before that warning appears.
If you really must use SMS, then I would suggest bundling multiple contacts together or batching the sends over time — short of rooting the phone, there is no way to get around this (sensible and useful) warning.
See also: http://groups.google.com/group/android-developers/browse_thread/thread/587f0d3a03ced88a
I think this a security check back to inform the user that an app is wasting a lot of money through sending a lot of SMS messages. If the use case of your app is valid you have to convince the user that sending all this messages is necessary and that he has to click the send button.
I hope and thinkg that there is no way to program around this because this a very sensible thing to do for a phone.