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.
Related
I have added multiple number under different categories for single user
like,
If I delete the one of the numbers , I want to detect which number got deleted from contact using ContactsContract content uris
The ContactsContract APIs can tell you that something changed in the Contacts table (via ContentObserver), but not what exactly.
If you want to detect the change that happened you'll need to keep and maintain a cache copy of all contacts in your app, you don't need to actual data itself, just the hash of each data row for each contact.
Then when you get your onChange called, you can go over all the data rows in the DB and compare them to the hashes you found the last time, and see if any were added/modified/deleted.
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...
In my android app on 4.2.1 I want to create a contact with some read only fields. For example, the contact the app creates has a home phone number which is read only in the UI. I will create a separate account where all these contacts are created.
I was looking at the android documentation and understand that all these contact fields become part of the Data table. But I dont see any column which can make the field read only.
There isn't a way to do this. Apps that work with the Contacts Provider have to request permission to write to it. If the user grants this permission to the app, then it can write to the Contacts provider.
The only thing you can do is create your own MIME type for the Data table, encrypt the data, and store each piece of data in a row that has that MIME type. Other apps can still see your data, but they have no way of figuring out what it is.
The Contacts Provider is a public repository, and you have to use it according to the rules it provides.
I am interested in your opinions on the best way to keep a robust reference to a contact starting android 2.0. I have read a lot regarding this issue but i don't know which technique is advisable and if there's any new ones. Below are the 3 options i found so far:
1- Don't use your own db. Extend the contacts.contract to write your data
2 - Use ContentObserver to keep track of any changes made to the contacts. This technique would however require your application to be running
3- Store all RAW contact IDs related to a CONTACT_ID in your db and infer the content of the aggregate contact from all its constituent RAW contacts
In my case i need to keep a separate db and i was wondering if there's any other new technique of keeping the CONTACT_ID current after aggregations and dis-aggregations...
Please advise
I am playing with the new Contacts API at the moment, writing an app which is also a source of contact data. I can't recommend #3 at all. To get all of "my" contact data I simply store them with a magic value in the RawContacts.SYNC1 field and query the contacts content provider for that when my app starts up.
Re. your question, don't use CONTACT_IDs, as they are volatile. Use the lookup API, i.e. if you have a raw contact ID, use RawContacts.getContactLookupUri() to get to the Contact. Likewise if some API gives you a contact ID, use Contacts.getLookupUri() to get a persistent identifier you can use later on.
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.