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

對不起兄弟,但我有看到這也在我的情況下這些沒有用。 –