我用的是android4.0的平台,用String data=bundle.getString("mess");//读出数据
String ph = bundle.getString("phone");
if (ph.length()>=11)
{
ph = ph.substring((ph.length()-11),ph.length());
}
String phName ="";
edSmsText.setText(data); String [] projectin ={ ContactsContract.PhoneLookup.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor phoneCursor = this.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectin, ContactsContract.CommonDataKinds.Phone.NUMBER+ " ='"+ph+"'", null, null);
if (phoneCursor== null)
{
edSmsText.setText(data+" 短信来自["+ph+"]");
}
else
{
if (phoneCursor.getCount()>0)
{
phoneCursor.moveToFirst();
int nameFieldColumnIndex = phoneCursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
phName = phoneCursor.getString(nameFieldColumnIndex);
edSmsText.setText(data+" 短信来自["+phName+"],手机号["+ph+"]");
}
else
{
Log.i("none", "none");
}
}
这段程序不好用,但在android2.1平台手机上好用。
String ph = bundle.getString("phone");
if (ph.length()>=11)
{
ph = ph.substring((ph.length()-11),ph.length());
}
String phName ="";
edSmsText.setText(data); String [] projectin ={ ContactsContract.PhoneLookup.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor phoneCursor = this.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectin, ContactsContract.CommonDataKinds.Phone.NUMBER+ " ='"+ph+"'", null, null);
if (phoneCursor== null)
{
edSmsText.setText(data+" 短信来自["+ph+"]");
}
else
{
if (phoneCursor.getCount()>0)
{
phoneCursor.moveToFirst();
int nameFieldColumnIndex = phoneCursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
phName = phoneCursor.getString(nameFieldColumnIndex);
edSmsText.setText(data+" 短信来自["+phName+"],手机号["+ph+"]");
}
else
{
Log.i("none", "none");
}
}
这段程序不好用,但在android2.1平台手机上好用。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货