How to display name of unknown incomming call number - android

In my app, I have a database of phone numbers. Each phone number has a name assigned to it.
When user receives incoming call from number that he has not saved in his contacts database I want to display name from my database instead of unknown label...
Is it possible? How can I achieve this?
Would it be possible to also display some additional labels? For example caller's company, gender, age... (all those information will be pulled from my database of course)

So I did some research and found this.
To change display name of incoming call number, I have to add a new contact. That may not be the best approach since it will create contact in user's contacts and will be preserved even after uninstalling the app...
Another option is to display overlay view on which can be shown name (and other labels) from my database. I think I will go with this solution...

Related

Android contacts how can I keep track of specific phone numbers for contact

My app lets the user select a contact using the contact picker. Afterward lets user selects one or phone phone number to be stored for later use (the numbers are stored in the db)
The trivial solution would have been to save the selected numbers to the database as strings. However I would like to avoid duplicating parts of the the device's contacts list and keep a link (e.g. a URI to a particular number) to that contact.
so far was not able to find a way to do that, the documentation states that the contact id itself might change, So I can only assume it also true for the contacts phone number.
am I missing something ?

How to add one extra field to contact database?

I want to add one field(column) to contact fields,that i can set value for that field in code and mobile user can not see that field in contact properties.In this way i can use contact information without create another database to copy contact database.
Is this possible?
please help me
I don't think you can modify the contacts database directly (or at least not without rooting the device first).
If you want to add additional information to a stored contact, I think your best option would be to actually create a new database. Just create a new table with columns [CONTACT_ID, YOUR_NEW_FIELD] and store that extra piece of information on the contact there. Also, that way you won't be polluting the contact's database with your app's proprietary information, which would have no meaning if the user removed your app.

How do I robustly compare phone numbers in Android?

In an Android app I am developing, I have a database which maps:
<Contact ID, Contact Lookup Key> --> <My Custom Data Associated with Contact>
When an incoming SMS message comes in, I want to be able to look up My Custom Data Associated with Contact associated with the contact who sent the SMS message. I want to do the lookup in as few steps as possible.
The only data I can get out of the SMS message is the Phone Number, so the problem is basically one of mapping the Phone Number to My Custom Data Associated with Contact in as few steps as possible.
Now, I am aware that I can look up a contact from a phone number up using ContactsContract.PhoneLookup as described e.g. here. However, this does not get me to my desired result because both the Contact ID and Contact Lookup Key are subject to change. So if either the ID or the Lookup Key has changed for any contact I have persisted to my database, I have to basically load my whole database and refresh the ID/Lookup Key for each row before I can test whether they represent the same contact as the one returned by ContactsContract.PhoneLookup. This is a pretty brutal solution which I would prefer to avoid.
What I would like to do is keep a table mapping phone numbers to my custom data (in an N:1 relationship).
<Phone Number> --> <My Custom Data Associated with Contact>
This way, in theory at least, I can index the phone number column and just look up the data in one step. However, phone numbers come in many formats. My solution will only work if I can create a canonical representation of a given phone number. My plan was to use PhoneNumberUtils.getStrippedReversed to produce an efficiently indexable canonical phone number, but this fails on a trivial case, for example:
PhoneNumberUtils.getStrippedReversed("+1(306)6656320") --> 02365566031
PhoneNumberUtils.getStrippedReversed("(306)6656320") --> 0236556603
They aren't the same number!
So with that by way of long-winded explanation, my question is: Can anyone think of a way of converting a phone number to a canonical phone number so that I can perform an indexed database lookup on the number, or any other solution to the problem I described above?
You can use below method along with getStrippedReversed
public static String toCallerIDMinMatch (String phoneNumber)
*Returns the rightmost MIN_MATCH (5) characters in the network portion in reversed order This can be used to do a database lookup against the column that stores getStrippedReversed() Returns null if phoneNumber == null*
Then your comparison will give you the desired result

Make changes to contacts

I'm making android app that tells you the operator's name of your contact's number.
Is there a way to put a label containing the name of the operator next to every number directly in the contacts list?
You will need to create your own sync provider and your own RawContacts table. Fill it up with name, phone number and the data you need (e.g., the operator name). Not an easy. task There's a very nice post with lots of details here:
http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/
There's an example in the android Technical Resources pages: http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

Possibility of a custom Contacts field with a set list of values and Contacts lookup performance

I'm pretty sure it's not viable to do what I'd like to based on some initial research, but I figured it couldn't hurt to ask the community of experts here in case someone knows a way.
I'd like to create a custom field for contacts that the user is able to edit from the main Contacts app; however, the user should only be allowed to select from a list of four specific values. A short list of string values would be ideal, but an int with a min/max range would suffice.
I'm interested in knowing if it's possible either way, but also wondering if it make sense to go this route performance wise. More specifically, would it be better to look up a contact (based on a phone number) each time a call or SMS message is received or better to store my own set of data (consisting of name, numbers, and the custom field) and just syncing contact info in a thread every so often? Or syncing contacts the first time the app is run and then registering for changes using ContentObserver?
Here is a similar question with an answer that explains how to add a custom field to a contact.
Thanks in advance.
I don't see the purpose to have your own set of data against contacts stored in your separate database, as you obviously will run into sync issues. You can use the mimetype and store whatever you want against the contact, in the manner you linked.
Whenever you want to looup contacts you can do that by using your custom mimetype. You get the contact id (from ContactsContract.Data.CONTENT_URI), and then you run another query to get the contact details (from ContactsContract.Contacts.CONTENT_URI). Please note these are different tables.
I'd like to create a custom field for contacts that the user is able to edit from the main Contacts app
I don't see that possible, editable from the main app, when you use your custom mimetypes, and you don't have much options here. The main contact app will display only the fields that are in SDK. You can store details against contacts but they won't show up in the inbuilt edit contact screen.

Categories

Resources