RT  有谁遇到过?
String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"};   
 Uri uri = Uri.parse("content://sms");   
 Cursor cur = getContentResolver().query(uri, projection, null, null, "date desc");
int nameColumn = cur.getColumnIndex("person");
name = cur.getString(nameColumn);

解决方案 »

  1.   

    String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"};   
             Uri uri = Uri.parse("content://sms");   
             Cursor cur = getContentResolver().query(uri, projection, null, null, "date desc");
    int nameColumn = cur.getColumnIndex("person");
    cur.moveToFirst();
    name = cur.getString(nameColumn);
      

  2.   

    应该不是这个问题吧我把那个完整的代码贴出来:
    private String getSMS()
    {
     String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"};   
     Uri uri = Uri.parse("content://sms");   
     Cursor cur = getContentResolver().query(uri, projection, null, null, "date desc");
     StringBuilder str = new StringBuilder();
     if (cur.moveToFirst()) 
     {
    String name;
    String phoneNumber;
    String sms;
    String id;
    String type;
    String date;

    int idColumn = cur.getColumnIndex("_id");
    int nameColumn = cur.getColumnIndex("person");
    int phoneColumn = cur.getColumnIndex("address");
    int smsColumn = cur.getColumnIndex("body");
    int dateColumn = cur.getColumnIndex("date");
    int typeColumn = cur.getColumnIndex("type");  

    do {
    int typeId = cur.getInt(typeColumn);   
        if(typeId == 1){   
            type = "接收";   

    else if(typeId == 2){   
        type = "发送";   

    else {
    type = "";
    }
        
        // 得到数据库中相应的数据
    name = cur.getString(nameColumn);
    phoneNumber = cur.getString(phoneColumn);
    sms = cur.getString(smsColumn);
    date = long2String(cur.getLong(dateColumn));
    id = cur.getString(idColumn);

    str.append("【");
    str.append(id + "    ");
    str.append(type + "\n");
    str.append(name + "   ");
    str.append(phoneNumber + "\n");
    str.append(sms + "\n");
    str.append(date);
    str.append("】");
    str.append("\n");
    str.append("\n");

    if (null == sms)
    sms = "";
    } while (cur.moveToNext());
     } 
     else {
     str.append("no result!");
    }
    Log.i("监听到的短信", str.toString()); //方便在eclipse的日志中看到效果。
    cur.close();
    return str.toString();
    }