Android software development contacts-add contacts and simple use of sqlite tools

Source: Internet
Author: User

For contacts to get contact information and the storage structure of contact information, the blogger of the following link has simply explained:

http://blog.csdn.net/snwrking/article/detail/7601794

--------------------------------------------------------------------------------------------------------------- -------------------

Back to the point, I was testing with a real machine, first connected to the computer with a data cable. The following article is just a little note of my own, hoping to help the needy friends. (It may be a bit verbose, but it's a little use for someone who doesn't.)

First, let's start with the code, and many people lose their "live" confidence because they can't write code:



First, I created a test package in the project: Com.example.test then create a test class that has a addphonecontacts () method that is used to write code that adds contact information.

--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------

Small episode:

You can use the File Explorer under Ddms to see where the contact information is stored (data/data/com.android.provider.contacts/databases below) How to use it, look down and know.

--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------

Since the above code adds the data to the table step after time when the contact is added, in order to be able to add data in bulk, the following code is used:



For adding other information, such as mailbox, landline, and so on, then write down on the line. (For those of you who just don't understand, there are a lot of similar codes on the Internet, as well as some explanations)

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------


Second, the Code test

Ps:

<application

<uses-library android:name= "Android.test.runner"/></application>

<instrumentation android:name= "Android.test.InstrumentationTestRunner"
Android:targetpackage= "Com.example.telephone" ></instrumentation>


Add the above two lines of code in manifest, and the targetpackage must be the same as the package, otherwise it will be an error.


In the test, we can run the test in Java mode by clicking on the method name right-outline, the test result is wrong I think I should be able to read.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------


Third, the Data View

At this point, we can check to see if the contact has been added successfully. (Of course, you can see the success in the phone book).

In Ddms, export the contacts.db file to a place under File Explorer, and then open the file with the SQLite Expert personal tool:




After opening, we found a lot of tables, but for just learning friends, just learn to draw the red circle of the three tables on it.

Open the data table and we'll see two horses. The owner's information has been added to the Address Book



Iv. use of the database in the code

1, Uri uri = Uri.parse ("content://com.android.contacts/raw_contacts");

URI = Uri.parse ("Content://com.android.contacts/data");

Gets the URI where the data is to be stored in the table's path.

Put ("column name", values);

Put ("MimeType", "vnd.android.cursor.item/name"); You can view it in the Mimetypes table


Amount:    A bit tired, first go to sleep a nap, and so on to perfect!  Wrong Hope someone told me , yes, I hope to help the needs of friends.


Android software development contacts-add contacts and simple use of sqlite tools

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.