を引数として取り、提供されたような電話番号を持つ連絡先に対してString
を返す関数を作成しようとしています。Contact_ID
String
私はすでに次のコードを見つけました
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を取得するにはどうすればよいですか?
ありがとう!