【问题标题】:Get contact name of the sender from the sms table?从短信表中获取发件人的联系人姓名?
【发布时间】:2011-08-08 12:41:09
【问题描述】:

我正在使用以下内容从收件箱中获取短信

ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(Uri.parse("content://sms"), null,null,null, null);        
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

     cursor_count=cur.getCount();

    if(cur.moveToFirst())
    {           
        do {

            sender.add(cur.getString(2));

            msg.add(cur.getString(11));
            date.add(formatter.format(Long.parseLong(cur.getString(4))));
        } while (cur.moveToNext());

我从地址字段中获取此人的地址,但我还想获取发件人的联系人姓名(如果存储在我的联系人中)。
person字段总是返回null,为什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    试试这个代码

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

    【讨论】:

    • 无法导入 PhoneLookup ??
    • 地址是联系电话。联系人 = cur.getString(2);或contact = cur.getString("address");
    • 请提供完整的工作代码或示例,因为我在获取所有 SMS 日志时不知道该代码的确切位置...
    • 将此代码放在您的广播接收器中,您将在其中收到新的短信,获取号码(地址)并继续使用我的代码,希望您能收到
    猜你喜欢
    • 2021-02-28
    • 1970-01-01
    • 2012-09-09
    • 2012-10-11
    • 1970-01-01
    • 2016-05-07
    • 2014-06-21
    • 1970-01-01
    相关资源
    最近更新 更多