0

我开发一个应用程序中,我访问来自身体,手机号码从地址消息,消息ID,人,给出了一个int值(我不知道是什么人)从这个代码:----这是可能的,从Android的收件箱访问名称?

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

其做工精细:--- 现在问题是 - 如果有任何手机号码保存在我的手机的联系人列表,比我想在我的ListView否则我想显示显示名称移动number这是我从address饲料访问。 如何,我会从收件箱Uri得到名称? 任何帮助将被赞赏。

感谢&问候, Deepanker

回答

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; 
     } 

+0

乌里uriSMSURI = Uri.parse( “内容://短信/收件箱”) ;使用此查询与上面的查询也那么问题的比较,如果messageAddress == Phone.DISPLAY_NAME显示显示名称,否则移动地址为了这个,我正在采取两个用于循环,使应用程序加载的我想从收件箱中的URI来访问,如果可能的 –

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)); 
          } 
+0

对不起兄弟,但我有看到这也在我的情况下这些没有用。 –