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, 2022 in Android by Edureka
• 13,620 points
1,050 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, 2022 by Edureka
• 12,690 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, 2022 in Android by Ashwini
• 5,430 points
2,918 views
0 votes
0 answers

"unable to locate adb" using Android Studio

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

Sep 21, 2022 in Android by Edureka
• 13,620 points
618 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, 2022 in Android by Edureka
• 13,620 points
1,338 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, 2022 in Android by Edureka
• 13,620 points
1,587 views
0 votes
0 answers

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

I am making an app that has ...READ MORE

Jun 7, 2022 in Others by polo
• 1,480 points
734 views
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,640 points
922 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,020 points
930 views
0 votes
1 answer

How to open the Google Play Store directly from my Android application?

If you want to link to your ...READ MORE

answered Nov 7, 2022 in Android by Edureka
• 12,690 points
4,325 views
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, 2022 in Android by Edureka
• 12,690 points
1,610 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