0

I am develop an App in which I access Message from body,Mobile Number from address,message id,person-gives a int value( i don't know about what is person) from this code:----

 Uri uriSMSURI = Uri.parse("content://sms/inbox");
 Cursor cur = getContentResolver().query(uriSMSURI , null, "read=0",
                null, null);

Its working fine:--- now the problem is that--If any mobile number is saved in my mobile contact list than i want to show the name in my ListView otherwise I want to show the mobile number which i access from address feed. How I will get Name from the Inbox Uri? Any Help will be Appreciated.

Thanks & Regards, Deepanker

4

2 回答 2

0

需要尝试这段代码

public String findNameByAddress(Context ct,String addr)
        {
             Uri myPerson = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
                        Uri.encode(addr));

             String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME };

                Cursor cursor = ct.getContentResolver().query(myPerson,
                        projection, null, null, null);

                if (cursor.moveToFirst()) {



                    String name=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));


                    Log.e("","Found contact name");

                    cursor.close();

                    return name;
                }

                cursor.close();
                Log.e("","Not Found contact name");

                return addr;
        }

于 2012-11-23T11:08:43.107 回答
0
String contact=address;
                           Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));  
                           Cursor cs= context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);

                           if(cs.getCount()>0)
                           {
                            cs.moveToFirst();
                            contact=cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
                           } 
于 2012-11-23T11:18:57.233 回答