Reputation: 23
I am trying to do Mobile Number Verification just like WhatsApp in my Android App. I'm able to send SMS from my Android app.
But I want to achieve these 2 things:
The Sender name in the receiver's Inbox should be a Custom Name decided by my App, like SMS from WhatsApp has sender name somewhat like WTAPP-5550. Currently its showing my Mobile Number.
Making sure that the SMS sent from User's phone doesn't show up in User's Sent Box. Currently SMS appears both as SENT and RECIEVED SMS. Like in d case of WhatsApp , no SENT Message is present only Recieved SMS is.
Thanks and Regards,
Rahul Soni
Upvotes: 1
Views: 2679
Reputation: 162
Sending Free SMS
private static final int MY_PERMISSIONS_REQUEST_SEND_SMS =0 ;
protected void sendSMSMessage() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);
}
}else if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
== PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);
}
}
}
permission
@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_SEND_SMS: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address" , new String ("01234"));
smsIntent.putExtra("sms_body" , "Test ");
try {
startActivity(smsIntent);
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this,
"SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
}
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(mobNo, "CP-ICTSBM", "Your otp is "+otp+" . "+"Do not share it with anyone by any means. This is confidential and to be used by you only. ICTSBM", null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.", Toast.LENGTH_LONG).show();
return;
}
}
}
}
In manifest permission added
<uses-permission android:name="android.permission.SEND_SMS" />
Upvotes: 0
Reputation: 3831
See Mr Rahul From your question what I understood is you are sending the sms to the mobile number through your app. That is not a good way to verify the mobile number. What you have to do is you have to send sms through the server. Whats app people will connect to their server and from server they will send sms to the entered mobile number. Thats why it will not appear in the sent box. And to set custom name to the sender number you have to use third party sms services.
Upvotes: 0