0

を引数として取り、提供されたような電話番号を持つ連絡先に対してStringを返す関数を作成しようとしています。Contact_IDString

私はすでに次のコードを見つけました

private String getContactName (String number) 
{
    String contactName = "";
    ContentResolver context = getContentResolver();

    /// number is the phone number
    Uri lookupUri = Uri.withAppendedPath(
    PhoneLookup.CONTENT_FILTER_URI, 
    Uri.encode(number));

    String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };

    Cursor cur = context.query(lookupUri,mPhoneNumberProjection, null, null, null);
    try 
    {
       if (cur.moveToFirst()) 
       {
          contactName = cur.getString(2);
          return contactName;
       }
    } 
    finally 
    {
        if (cur != null)
            cur.close();
    }
    return contactName;
}

指定された番号のすべてのcontactsNameを返します。ここから連絡先IDを取得するにはどうすればよいですか?

ありがとう!

4

1 に答える 1

0

cur.getString(2)に置き換えるだけですcur.getString(0)。あなたはすでに_ID射影の一部として を持っています (ところで、これは だけに減らすことができます_ID)。

于 2013-02-27T21:45:14.113 に答える