Content provider is an abstract data encapsulation and data access mechanism, such as SQLite is a data source with an Android device that can be encapsulated into a content provider. To read and write through the content provider, you need to use a URI. Recommended Read Android Learning Note (47): Content provider and Android contact information, Android learning Note (48): Provide your own content Provider and Android Learning notes (49): Access data via content provider. Content provider's important role is to achieve data sharing between applications, and for in-app data access, Android offers a variety of ways, with preferences, files, SQLite, and access to the Internet through the HTTP service.
Android has some built-in content Provider that we can view in the Android.provider package, such as Contact,mediastore, which is not built-in, and must be implemented via the content Provider interface.
Android's Database
SQLite is a common source of data for content providers. We can use the commands of Android and SQLite to process SQLite data, which are located in/sdk/tools and/sdk/platform-tools. To facilitate the use of these commands, we set the script file Myandroid.bat in Windows to set the environment variables. In Linux, you can $PATH by export path=: $HOME/... To set it up.
Set SDKPATH=D:\DEVELOPER\ADT-BUNDLE-WINDOWS-X86\ADT-BUNDLE-WINDOWS-X86-20130522\SDK
Path=%path%;%sdkpath%\tools;%sdkpath%\platform-tools
Android provides ADB commands to operate on an emulator or connected device. The ADB, or Android Debug Bridge, can be read in http://developer.android.com/tools/help/adb.html with detailed commands.
In the previous we have learned to use adb devices to view the currently active devices. If the device is not connected or the emulator is not enabled, we can turn on the emulator by emulator @avdname , and Avdname is the name of the AVD, and the valid Avdname can be via the Android list AVD command to view, of course we can open through eclipse.
Use the following command to operate on the connected device or emulator.
ADB shell
Once in, we can view the commands that can be used by Ls/system/bin . The data information is stored in the /data/data directory, categorized by the installation package. We can take a look at those packages with the SQLite database under the ls–r/data/data/*/databases . For example, some DB built into Android.
These *.db files are on the SQLite database. The Android database is usually created at the time of the first visit. To approach the database using:
sqlite3 /data/data/< package name. For example com.android.providers.contacts>/databases/< database file:contacts.db>
Here are some common SQLite commands:
Sqlite>.exit Exit SQLite
Sqlite>.tables Show Tables List
You can use the SQL language as well as the semicolon at the end.
From the perspective of the. Schema table_name, we can copy the *.db file and view it with specialized database tools, such as Sqliteman, or you can do it locally via the sqlite3 command. The command to drag the file out is as follows, do not fill in the < local path, or the current directory.
Common SQL language
Record some common SQL languages.
SELECT * FROM table1;
Select COUNT (*) from table1;
Select col1, col2 from table1;
SELECT DISTINCT col1 from table1;
Select COUNT (col1) from (select DISTINCT col1 from table1);
Select COUNT (*), col1 from table1 Group by col1;
SELECT * FROM table1 T1, table2 t2 where t1.col1 = t2.col1;
SELECT * FROM table T1 left outer joins table2 t2 on t1.col1 = t2.col1 where ....
RELATED Links: My Android development related articles
Transfer from http://blog.csdn.net/flowingflying/article/details/9185809
"Turn" Pro Android Learning Note (v): Learn about content Provider (top)