【问题标题】:Is it Possible ,To access Name from Inbox in Android?是否可以从 Android 的收件箱中访问名称?
【发布时间】:2012-11-23 11:02:04
【问题描述】:

我正在开发一个应用程序,我在其中访问 来自正文的消息,来自地址的手机号码,消息 id,person-给出一个 int 值(我不知道什么是 person)代码:----

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

它工作正常:--- 现在问题是——如果我的手机联系人列表中保存了任何手机号码,我想在我的ListView 中显示姓名,否则我想显示我访问的手机number来自address 饲料。 我如何从收件箱Uri 中获取姓名? 任何帮助将不胜感激。

感谢和问候, 深潘克

【问题讨论】:

    标签: android message android-contentprovider android-contacts inbox


    【解决方案1】:

    需要试试这个代码

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

    【讨论】:

    • Uri uriSMSURI = Uri.parse("content://sms/inbox");使用此查询和上述查询,然后比较问题是否 messageAddress==Phone.DISPLAY_NAME 显示显示名称,否则移动地址为此我需要两个 for 循环,因此应用程序已加载,如果可能,我想从收件箱 uri 访问
    【解决方案2】:
    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));
                               } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 2011-05-29
      相关资源
      最近更新 更多