Open contact information in your contact list using Contact Studio for Android phone number

I am making a small application that is related to phone numbers.

My question is: I have a phone number that is on my contact list in my phone. Example: 0877777777

I would like to open this contact information using this phone number.

Just to clarify, when I talk about the contact list, I mean the contacts stored on my phone.

If anyone could help me, I would appreciate it.

+4
source share
1 answer

PhoneLookup The api is just for that.

String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };

Cursor cur = getContentresolver().query(uri, projection, null, null, null);

if (cur != null) {
   while (cur.moveToNext()) {
      Long id = cur.getLong(0);
      String name = cur.getString(1);
      Log.d("My Contacts", "found: " + id + " - " + name);
   }
   cur.close();
}

UPDATE

, CONTACT_ID, Intent :

String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID };

Cursor cur = getContentresolver().query(uri, projection, null, null, null);

// if other contacts have that phone as well, we simply take the first contact found.
if (cur != null && cur.moveToNext()) {
    Long id = cur.getLong(0);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(id));
    intent.setData(contactUri);
    context.startActivity(intent);

    cur.close();
}
+2

Source: https://habr.com/ru/post/1681028/


All Articles