Android Development Series logs-(4)

Source: Internet
Author: User

1. contentprovider
1. What is contentprovider
Contentprovider is one of the four Android components used Program To other programs.
When sharing data Code Encapsulated as a method without directly exposing the data to improve security.
You can register a contentobserver for contentprovider to monitor data modification in real time.
2. How to create and access contentprovider *****
Define the class to inherit contentprovider and register the <provider> node in the <Application> node in the configuration file.
After the program is installed on the mobile phone, other applications can access it.
Obtain the contentresolver object during access, specify the URI, and call the add, delete, modify, and query method.
3. Details in contentprovider ***
In contentprovider, table names can be identified by URIs to identify IDs.
You can use the urimatcher class to identify a path, call the adduri () method to add a path, and then use the match () method to match a URI to obtain the preset result code.
The ID carried in the URI can be obtained using the parseid () method of the contenturis class.
After the insert method is executed, a URI with an ID needs to be returned. You can also use the withappendedid () method of the contenturis class to complete the operation.
4. Use contentobserver to observe the data changes of contentprovider *****
You can use the registercontentobserver () method of contentresolver to register a contentobserver on the specified Uri.
The onchange () method of contentobserver is automatically executed when ontentprovider calls the contentresolver. policychange () method.

Ii. Monitor text messages
1. Use git to download Source code
View the list and obtain authorities. view the Java code to learn about the sub-path.
2. Add an observer
Register an observer with the content provider of the SMS data in the system. When the data changes, query the last record.
Obtain the address, type, date, and body fields.

3. operation contact
1. download Code *
similar to the text message code, use git to download the code and find the authorities and sub-path
2. read contact ***
first read the raw_contacts table to get all IDs
use ID as the query condition to query the data table. mimetype is the data type, and data1 is the data
3. write a contact
first write an automatically generated ID to the raw_contacts table
then use the ID as the value of the raw_contact_id column in the data table, insert data
multiple insert operations should be a group of operations, either successful or failed
you can use the applybatch () method of the contentresolver class

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.