码迷,mamicode.com
首页 > 移动开发 > 详细

Android 短信收件人自动匹配与用户输入的显示不一致

时间:2014-08-29 16:10:58      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:des   android   os   java   io   ar   for   问题   cti   

1.将号码“12345678”存为联系人Test后
2.进入短信编辑界面,在收件人一栏输入“13712345678”,再切换到文字输入框,使收件人那个控件失焦,可以看到收件人立即显示为“Test”,再返回去点击那个收件人,发现目标号码变成了“12345678”。
3.发送信息,提示发送失败。
PS:用户本来想要把短信发送到“13712345678”的,结果因为电话薄里面存了个“12345678”的联系人,系统就把发送目标的号码给变更了,导致信息发送失败。

号码匹配相关的问题都可以先用以下方式验证,如果还有异常,请提交eService到mediatek.
alps\frameworks\ex\chips\src\com\android\ex\chips\RecipientAlternatesAdapter.java中getRecipientEntryByPhoneNumber() 替换成下面的code:


    public static RecipientEntry getRecipientEntryByPhoneNumber(Context context, String phoneNumber) {
        Log.d(TAG, "[getRecipientEntryByPhoneNumber] phoneNumber: " + phoneNumber);    /// M: MTK debug log
        if (phoneNumber == null || TextUtils.isEmpty(phoneNumber)) {
            return null;
        }
        final String[] PHONE_LOOKUP_PROJECTION = new String[] {
                    Phone._ID,                      // 0
                    Phone.CONTACT_ID,               // 1
                    Phone.NUMBER,                   // 2
                    Phone.NORMALIZED_NUMBER,        // 3
                    Phone.DISPLAY_NAME,             // 4
                };
        long index = -1;
 String currentNumber = "";
        String normalizedNumber = PhoneNumberUtils.normalizeNumber(phoneNumber);
        /// M: Query CONTACT_ID by giving phone number
        Cursor cursorNormalize = context.getContentResolver().query(
                        Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, normalizedNumber), PHONE_LOOKUP_PROJECTION, null, null, null);
        /// M: Return null if query result is empty
        if (cursorNormalize == null) {
            Log.d(TAG, "[getRecipientEntryByPhoneNumber] cursorNormalize is null");    /// M: MTK debug log
            return null;
        }
        if (cursorNormalize.moveToFirst()) {
            do {
                index = cursorNormalize.getLong(1); /// M: Phone.CONTACT_ID
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "[getRecipientEntryByPhoneNumber] Query ID for " + phoneNumber
                            + " RESULTS: "
                            + " NAME : " + cursorNormalize.getString(4)
                            + " CONTACT ID : " + cursorNormalize.getLong(1)
                            + " ADDRESS :" + cursorNormalize.getString(2));
                }
            } while (cursorNormalize.moveToNext());
        }
        cursorNormalize.close();
        /// M: No matched contact
        if (index == -1) {
            return null;
        }
        /// M: Query contact information by giving CONTACT_ID
 RecipientEntry entry = null;
        for (long i = index; i > 0; i--) {
        Log.d(TAG, " getRecipientEntryByPhoneNumber i = "+ i);
        Cursor cursor = context.getContentResolver().query(
                        Queries.PHONE.getContentUri(),
                        Queries.PHONE.getProjection(),
                        Queries.PHONE.getProjection()[Queries.Query.CONTACT_ID] + " IN (" + String.valueOf(i) + ")", null, null);
        if (cursor.moveToFirst()) {
            do {
      if (cursor.getString(Queries.Query.DESTINATION).length() < currentNumber.length())
      break;
                if (true) {
                    Log.d(TAG, "[getRecipientEntryByPhoneNumber] Query detail for " + phoneNumber
                            + " RESULTS: "
                            + " NAME : " + cursor.getString(Queries.Query.NAME)
                            + " CONTACT ID : " + cursor.getLong(Queries.Query.CONTACT_ID)
                            + " ADDRESS :" + cursor.getString(Queries.Query.DESTINATION));
                }
                currentNumber = cursor.getString(1);  /// M:Phone.NUMBER
                if (PhoneNumberUtils.compare(PhoneNumberUtils.normalizeNumber(currentNumber), normalizedNumber)) {
                    entry = RecipientEntry.constructTopLevelEntry(
                        cursor.getString(Queries.Query.NAME),
                        cursor.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
                        cursor.getString(Queries.Query.DESTINATION),
                        cursor.getInt(Queries.Query.DESTINATION_TYPE),
                        cursor.getString(Queries.Query.DESTINATION_LABEL),
                        cursor.getLong(Queries.Query.CONTACT_ID),
                        cursor.getLong(Queries.Query.DATA_ID),
                        cursor.getString(Queries.Query.PHOTO_THUMBNAIL_URI),
                        true, false);
                    break;
                }
            } while (cursor.moveToNext());
        }
        Log.d(TAG, "[getRecipientEntryByPhoneNumber] cursor count: " + (cursor != null ? cursor.getCount() : "null"));    /// M: MTK debug log
        cursor.close();
        }
 if (phoneNumber.length() - entry.getDestination().length() != 3 || entry.getDestination().length() < 11) {
            Log.d(TAG, " the query do not meet the conditon, drop it");
            entry = null;
 }
        return entry;
    }
注意事项:


   1. 先mm build   frameworks/ex/chips
    2. 然后 mm build packages/app/Mms
将生成的Mms push 到手机

Android 短信收件人自动匹配与用户输入的显示不一致

标签:des   android   os   java   io   ar   for   问题   cti   

原文地址:http://blog.csdn.net/sergeycao/article/details/38847555

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!