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

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 到手机

时间: 2024-10-08 12:13:41

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

android 短信验证自动获取验证码

权限: <uses-permission android:name="android.permission.RECEIVE_SMS" /> activity类 import java.util.regex.Matcher; import java.util.regex.Pattern; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Bro

Android短信彩信收发流程(应用层)

下图为ComposeMessageActivity中confirmSendMessageIfNeeded部分的信息发送流程.主要以接收者有效性的确认为主,然后转向sendMessage方法进行发送. ComposeMessageActivity.sendMessage从下图可以看出,在这个方法中,主要做的事是确认手机状态的有效性.最终调用WorkingMessage的send方法进行信息的发送.  WorkingMessage.send从下图可以看出,在本方法中,对于不同类型的消息,分别调用不同

初识安卓小程序(Android短信发送器)

首先,先创建一个安卓项目(我的版本是4.4.2的),名字为"短信发送器" 然后在res文件夹下找到layout文件夹,找到activity_main.xml或fragment_main.xml,在里面输入或拖拽按钮 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool

Android短信监听(三)——利用Loader实现短信监听

MainActivity如下: package cc.c; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.app.LoaderManager.LoaderCallbacks; import android.content.Context; import android.content.Loader; import android.database.Curs

Android短信监听(二)——利用ContentObserver实现短信监听

MainActivity如下: package cc.testsmslistener; import cc.testsmslistener.SMSContentObserver.MessageListener; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.widget.TextView; import android.app.Activity; /** *

Android短信监听(一)——利用BroadcastReceiver实现短信监听

MainActivity如下: package cc.testsmsbroadcastreceiver; import cc.testsmsbroadcastreceiver.SMSBroadcastReceiver.MessageListener; import android.os.Bundle; import android.widget.TextView; import android.app.Activity; /** * Demo描述: * 利用BroadcastReceiver实现

Android -- 短信

背景                                                                                           主要代码                                                                                      发送按钮的监听器: phone_number_editText = (EditText) findViewById(R.id.phon

Android短信插入器源码

package com.examp.createsms; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.net.Uri; import android.os.Bundle; public class MainActivity extends Activity { @Override protected

Android 短信的还原

上篇文章讲到<Android 短信的备份>,本文主要实现Android 短信的还原,即是将一条 布局文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" andr