Android phone defender's Get contact information display and echo _android

Source: Internet
Author: User
Tags one table

The previous article has implemented the related layout, this article then carries on the related function realization

Read system contacts
When you click the "Select a Contact" button, pop-up contact list, read the system contact is divided into the following steps:

The system contact provides a content provider that matches the URL address through the content parser

1. Content Parser

2.URL address, view system contact database, content provider source

First look at the API document's manifest file, and then look at the Java class (contact database has more than one table)

contents://com.android.contacts/Table Name

3. Table structure of the core table in the system contact database

Raw_contacts Contact table: contact_id Contact Uniqueness ID Value

Data User Information table: raw_contact_id as a foreign key, and raw_contacts contact_id to do the associated query

Get the Data1 field, including the phone number and contact name

mimetype_id field, containing the corresponding data type for the current row data1

Mimetypes Type table: Get the mimetype_id and mimetypes in the data table to do the associated query, get the type of information pointed to
Telephone Number: VND.ANDROID.CURSOR.ITEM/PHONE_V2
User name: Vnd.android.cursor.item/name

4. How the table is accessed

Content://com.android.contacts/raw_contacts
Content://com.android.contacts/data

The following code is used to implement

  Private ListView lv_contact;
  Private list 

The effect of the implementation is as follows:

Contact Info Echo

Next implementation clicks the contact item, realizes the Echo, for example double clicks the first entry, the number automatically adds

The code is as follows:

  private void Initui () {
    lv_contact = (ListView) Findviewbyid (r.id.lv_contact);
    Lv_contact.setonitemclicklistener (New Adapterview.onitemclicklistener () {
      @Override public
      Void Onitemclick (adapterview<?> adapterview, view view, int I, long l) {
        //1, gets the index of the entry in the point to point to the object in the collection
        if (Madapter!= NULL) {
          hashmap<string, string> HashMap = Madapter.getitem (i);
          2, get the current entry point to the set corresponding to the phone number
          String phone = hashmap.get ("phone");
          3, this phone number needs to give the third navigation interface to use

          //4, at the end of this interface back to the previous navigation interface, you need to return the data to the past
          Intent Intent = new Intent ();
          Intent.putextra ("Phone", phone);
          Setresult (0, intent);
          Finish ();}}}
    );
  

Then add the following code in the Onactivityresult

  @Override
  protected void onactivityresult (int requestcode, int resultcode, Intent data) {
    if (data!= null) {
      1, return to the current interface, the method of accepting the result
      String phone = Data.getstringextra ("phone");
      2, filter special characters (convert the underscore to an empty string)
      phone = phone.replace ("-", ""). Replace ("", ""). Trim ();
      Et_phone_number.settext (phone);

      3, store contact person to SP
      sputil.putstring (Getapplicationcontext (), Constantvalue.contact_phone, PHONE);
    Super.onactivityresult (Requestcode, ResultCode, data);
  }

When you fill in the number, go to the next page, return again, find the number is missing, and then use the SP store and read from

  private void Initui () {
    ///Displays the input box for the phone number
    Et_phone_number = (edittext) Findviewbyid (r.id.et_phone_number);
    Get contact phone number echo process
    String Contact_phone = sputil.getstring (This, Constantvalue.contact_phone, "");
    Et_phone_number.settext (contact_phone);
    Bt_select_number = (Button) Findviewbyid (r.id.bt_select_number);
    Click to select a contact's dialog box
    Bt_select_number.setonclicklistener (New View.onclicklistener () {
      @Override public
      Void OnClick (view view) {
        Intent Intent = new Intent (Getapplicationcontext (), contactlistactivity.class);
        Startactivityforresult (Intent, 0);}}
    );
  

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.