Add a location group to the Android contact

Source: Internet
Author: User

 

Previously, we were responsible for collecting contacts and adding locations to the company's two smart groups. There were many implementation methods on the Internet, some of which said that webserver was used for queries, but the network form was not a long-term approach; after all, the server is not yours, and there are many other unstable factors. Next, we will mainly introduce how this group is implemented.

It is achieved by creating a third-party local database. I used nationwide mobile phone home data records in the middle of. When I got the data, I was terrified. There were more than million mobile phone home records nationwide. Under normal circumstances, each mobile phone stores more than 100 contacts. The method I used is to first retrieve all the region information and save it in the configuration file. If there is an operation to add or modify contacts, refresh all the configuration files. The total refresh for more than one hundred people is about 4 ~ Around 5 seconds, the user can hardly feel it if there are dozens of people. Therefore, this efficiency is feasible. The following describes how to create a third-party database (the program runs to copy the database to the corresponding package name of the data Directory) and process data.

First, let's analyze the mobile phone number. The first three of the first seven digits of the mobile phone number are carrier information, and the last four digits of the first seven digits are region information. Therefore, we should divide so much data into small modules as much as possible, so that the range of each query can be reduced to improve efficiency. The numbers of carriers are listed below:

286764 data entries
China Telecom 133-> 9648 China Telecom 153-> 9818 China Telecom 180-> 9577 China Telecom 189-> 9988
China Telecom 181-> 8263 mobile 134-> 9694 mobile 135-> 10000 mobile 136-> 10000
Move 137-> 9976 move 138-> 9994 move 139-> 9998 move 150-> 10000
Move 151-> 10000 move 152-> 10000 move 157-> 7096 move 158-> 10000
Move 159-> 10000 move 182-> 9960 move 183-> 9975 move 184-> 4879
Mobile 187-> 9980 mobile 188-> 9546 Unicom 130-> 9884 Unicom 131-> 10000
China Unicom 132> 9804 China Unicom 155> 10000 China Unicom 156> 9781 China Unicom 185> 6983
China Unicom 186-> 9684 data card 145-> 5883 data card 147-> 6358

Now you should know what I think, that is, to insert 0.28 million pieces of data into 31 tables according to different filtering methods from the first three (write code read from the file and insert it in, it takes several hours before and after ). Finally, all the tables in my third-party database are named:

D --> Telecom l --> Unicom s --> Unicom data card y --> mobile
Public static final String [] TableArray = new String [] {
Dda-, d153, d180, d181, d189,
L130, l131, l132, l155, l156, l185, l186,
S145, s147,
Y134, y135, y136, y136, y138, y139, y150, y151, y152, y157, y158, y159, y182, y183, y184, y187, y188
};

The table structure is as follows (after the database is exported, the Sqliteman tool opens the DB file for viewing ):

Every time the number obtained from the database is 13755555551, the first three digits of the number are 137, so we should take the first seven digits of the number 1375555 to go to the table "y137 query region information. My logic is that if the number is not 11 characters long, no address information items will be included. If no record is found after the query, no address information items will be included.

In this case, the db size is about 8 MB, which is very high and the efficiency is acceptable. The next article will slim down the data and try to compress it to about 1 MB. It is estimated that million records will be compressed into rows, and the query efficiency will be improved.

 

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.