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

  • SEARCH
  • Home
  • 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 9156675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:49:34+00:00 2026-06-17T12:49:34+00:00

I am working on android app that receives a broadcast intent for incoming calls

  • 0

I am working on android app that receives a broadcast intent for incoming calls and incoming text messages.

It then is supposed to get the incoming number and perform a search on the users contacts using the incoming number.

This is more a less working, but I am having a slight problem. I have it working so that the number is searched in the contact list by, if it starts with + strips the first 3 characters and puts a 0 on the beginning, or just a does a search if it doesn’t contain the +. However, I have a slight problem, that if the user enters spaces in the number then the app doesn’t find the contact. For example, if I have a contact number saved as 07412xxxxxx and the incoming number comes in as 07412xxxxxx or +447412xxxxxx. However, if the contact number is saved as `07412 xxx xxxand the incoming number is07412xxxxxx“ then the number doesn’t get recognised so it doesn’t find the contacts name.

How can I perform the search to take all considerations of the number format. Below is the code I am currently using.

public String getContactNameFromNumber(String number)
    {

        if (number.startsWith("+"))
        {
            number = "0" + number.substring(3);
        }

        String contactName = null;
        ContentResolver contentResolver = context.getContentResolver();

        Uri uri = Data.CONTENT_URI;
        String[] projection = new String[] {PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
        String selection = ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?";
        String[] selectionArgs = { number };
        Cursor cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);

        if (cursor.moveToFirst())
        {

            contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
            cursor.close();
            return contactName;
        }
        else
        {
            cursor.close();
            return null;
        }
    }
  • 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-17T12:49:36+00:00Added an answer on June 17, 2026 at 12:49 pm

    Try:

    String selection = "REPLACE (" + ContactsContract.CommonDataKinds.Phone.NUMBER + ", \" \" , \"\" ) = ?";
    

    See replace function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I was working on an android application that sends and receives text messages,
I have an app that listens for incoming calls and depending upon the number
I am currently working on an app for Android that receives data from server.
I am working on an Android app that utilizes the Google Maps API MapView,
I am working on an android app that has a database in which one
I have an Android app that I had working a few months ago which
I'm working on an App that runs a webservice hosted an Android device. I'm
I am working on a Corona sdk lua app for Android devices that does
I'm working on an android app that writes and reads .PNG files from sdcard.
I am working on an Android app that uses the gdata-java-client to download documents

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.