简体   繁体   English

发送短信的标准格式电话号码是什么?

[英]What is standard format phone number to send SMS?

My app used SMSManager to send SMS to number which saved in Contact List 我的应用程序使用SMSManager将SMS发送到联系人列表中保存的号码

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

I got feedback from user, some number in their contact list can not receive SMS from the app. 我收到了用户的反馈,他们的联系人列表中的某些号码无法从该应用程序接收短信。 Seem this issue relate with format phone number for each country. 似乎此问题与每个国家/地区的电话号码格式有关。

A user from US feedback the Phone Number of this format can not receive SMS. 来自美国的用户反馈此格式的电话号码无法接收SMS。 Number : (555)444-6666 号码:( 555)444-6666

I think I should convert the phone number to a "standard" phone number before sending SMS. 我认为我应该在发送SMS之前将电话号码转换为“标准”电话号码。

What is standard format phone number should I use? 我应该使用什么标准格式的电话号码?

If I remove all special character of number from (555)444-6666 to 5554446666 , this way is a good way to apply for all country ? 如果我将数字的所有特殊字符从(555)444-6666删除5554446666 ,这种方法是在所有国家/地区申请的好方法吗?

there is no standard needed to send messages. 不需要发送消息的标准。

You can copy and paste this code to retrieve contact phone number. 您可以复制并粘贴此代码以检索联系人电话号码。

private String readcontacts(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 number
                    Cursor pCur = cr
                            .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                    null,
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                            + " = ?", new String[]{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. 您只需要在此方法中指定联系人姓名“ cName,Android系统就会以正确的格式返回电话号码。

and then send SMS. 然后发送短信。

public void sendSMS(String message) {

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM