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