Open Contact information in Contact List using Phone Number of Contact Android Studio

0 votes
I'm developing a simple app that deals with phone numbers.

My concern is that I have a phone number in my phone's Contact List. as in 0877777777

I want to dial that phone number to access those contacts.

Just to be clear, I refer to my phone's contacts when I talk about my contact list.

I would be grateful if someone could assist me.
Nov 3 in Android by Edureka
• 12,390 points
49 views

1 answer to this question.

0 votes

You must first obtain the contact's CONTACT ID before using it in an Intent to the external app in order to access the contact's profile in the stock contacts app:

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();
}
answered Nov 7 by Edureka
• 10,880 points

Related Questions In Android

0 votes
0 answers

How to open WhatsApp using an Intent in your Android App?

I want an Intent to take control ...READ MORE

Nov 23 in Android by Ashwini
• 2,760 points
44 views
0 votes
0 answers

"unable to locate adb" using Android Studio

I've been attempting to test my software ...READ MORE

Sep 21 in Android by Edureka
• 12,390 points
103 views
0 votes
0 answers

Unable to detect adb version, adb output in Android Studio 3.3.2

I have done following task for solutions; Download ...READ MORE

Sep 21 in Android by Edureka
• 12,390 points
202 views
0 votes
1 answer

What is the purpose of setImageResource() in Android?

setImageResource(): Use a resource id to set the ...READ MORE

answered Nov 8 in Android by Edureka
• 12,390 points
55 views
0 votes
0 answers
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,630 points
426 views
0 votes
1 answer

Can't find class CognitoUserPoolsSignInProvider: Issue with Sign In integration

CognitoUserPoolsSignInProvider is ditributed as part of aws-android-sdk-auth-userpools library. Please import ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,100 points
343 views
0 votes
1 answer
0 votes
1 answer

How to turn on front flash light programmatically in Android?

For this problem you should: Check whether the ...READ MORE

answered Nov 8 in Android by Edureka
• 10,880 points
43 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP