Skip to content Skip to sidebar Skip to footer

What Is Standard Format Phone Number To Send Sms?

My app used SMSManager to send SMS to number which saved in Contact List SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage('phoneNo', null, 'sms message',

Solution 1:

there is no standard needed to send messages.

You can copy and paste this code to retrieve contact phone number.

privateStringreadcontacts(Context context, String cName) {
    ContentResolver cr = context.getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(cur
                    .getColumnIndex(ContactsContract.Contacts._ID));
            String name = cur
                    .getString(
                            cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))
                    .toLowerCase();
            if (name.equals(cName.toLowerCase())) {
                if (Integer
                        .parseInt(cur.getString(cur
                                .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                    // get the phone numberCursor pCur = cr
                            .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                    null,
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                            + " = ?", newString[]{id},
                                    null);
                    while (pCur.moveToNext()) {
                        String phone = pCur
                                .getString(pCur
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        return phone;
                    }
                    pCur.close();
                }
            }
        }
    }
    return"Nothing found for " + cName + "!";
}

You just need to specify the contact name "cName" in this method and android system will return the phone number in correct format.

and then send SMS.

publicvoidsendSMS(String message) {

    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(readcontacts(context, "john"), null, message, null, null);

}

Post a Comment for "What Is Standard Format Phone Number To Send Sms?"