Reputation: 1
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!
Upvotes: 0
Views: 1440
Reputation: 4370
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.
Upvotes: 1
Reputation: 73956
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);
Upvotes: 1