Search code examples
androidandroid-contacts

How to read contents of "contacts2.db" file from the phone programmatically?


Is it possible to read the database files in Android 2.1 ? For example, files in /data/data/com.android.providers.contacts/databases/ contacts2.db. If yes, how? And is it possible to replace this file programmatically in order to import / export contacts or any other database files?


Solution

  • You would never access

    /data/data/com.android.providers.contacts/databases/contacts2.db
    

    EVER. You can't read that file from your app without root access anyways. What your looking for is content providers. As the URI specifies that is a provider to the contacts database. You want to look more into Content Providers and specifically in your case the Contact Provider. You can look at the documentation here: http://developer.android.com/guide/topics/providers/contacts-provider.html

    Hope that answers your question.