Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:23:22+00:00 2026-06-05T19:23:22+00:00

I have this method to display the contact numbers in my inbox: public ArrayList<String>

  • 0

I have this method to display the contact numbers in my inbox:

    public ArrayList<String> fetchInboxNumbers() {

    ArrayList<String> sms = new ArrayList<String>();
    Uri uriSms = Uri.parse("content://sms/inbox");
    Cursor cursor = getContentResolver().query(uriSms,
            new String[] { "_id", "address", "date", "body" }, null, null, null);

    cursor.moveToFirst();
    while (cursor.moveToNext()) {

        address = cursor.getString(1); // Displays phone number


        Log.d("CONTACT", address);
        sms.add(address); // + " " + body
    }

    Log.d("NAMES IN CALLLOG", sms.get(7));

    return sms;
} // END FETCHINBOX

What I’m trying to do is change String address to its contact name.

From fetchContactNumbers() and ‘fetchContactNames(), how can I changeaddress` to a contact name?

Its important to understand that fetchContactNumbers and fetchContactNames() are aligned, meaning fetchContactNumbers().get(5)‘s contact name is fetchContactNames().get(5)`.

In the end, fetchInboxNumbers() populates a custom adapter.

This method returns a list of all contact names:

public ArrayList<String> fetchContactNames() {

    ArrayList<String> names = new ArrayList<String>();
    Cursor phones = getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
            null, null);
    while (phones.moveToNext()) {

        String name = phones
                .getString(phones
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        names.add(name);
    }
    phones.close();

    return names;
} 

And this method lists all phone numbers:

public ArrayList<String> fetchContactNumbers() {

    ArrayList<String> numbers = new ArrayList<String>();
    Cursor phones = getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
            null, null);
    while (phones.moveToNext()) {
        String phoneNumber = phones
                .getString(phones
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        numbers.add(phoneNumber);
    }
    phones.close();

    return numbers;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:23:25+00:00Added an answer on June 5, 2026 at 7:23 pm

    You can use CONTENT_FILTER_URI to get the display name, instead of getting all names and numbers separately, something like below:

    public ArrayList<String> fetchInboxNumbers() {
        String displayName = "";
        ArrayList<String> sms = new ArrayList<String>();
        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor cursor = getContentResolver().query(uriSms,
            new String[] { "_id", "address", "date", "body" }, null, null, null);
    
        cursor.moveToFirst();
        while (cursor.moveToNext()) {
            address = cursor.getString(1); // Displays phone number
            displayName = getDisplayName(address);
            sms.add(displayName); // + " " + body
        }
        return sms;
    } // END FETCHINBOX
    
    private String getDisplayName(String phoneNumber) {
        String displayName = ""; 
        Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,      Uri.encode(phoneNumber));
        Cursor cursor = context.getContentResolver().query(uri, new String[] { Phone._ID, Phone.DISPLAY_NAME}, null, null, null);
    
        if (cursor.moveToFirst()) {
    
            displayName =  cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
        }
        return displayName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method AddSection public ActionResult AddSection(string code, ArrayList added) { ArrayList list
I have this method: public ActionResult MyMethod(string email, MyComplexObject json) When I call it
I have this method that logs errors from the Silverlight client: [MethodImpl(MethodImplOptions.NoInlining)] public static
I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public
Ok, this is homework. I have an arraylist assignment to add, display, search and
I have this method (someone else wrote it!) - (IBAction)showMasterPopover:(id)sender { if (_hiddenPopoverController &&
I have this method that usually works, but lately it has been giving me
i have this method - NSArray *objects = [NSArray arrayWithObjects:appDelegate.UserID,itemName.text,@1,@1,itemDegem.text,itemDescription.text, nil]; NSArray *keys =
I have this method: + (MHTwitterParser*)createParser:(NSString*)format { if ([format compare:@json] == NSOrderedSame) { return
I have this method to save a mutable array named myWallet that contains instances

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.