In the previous blog: android--lock launch-native browser boot-boot provision as well as android--sqlite3 Basic command operation have analyzed to Android boot real boot apk and its tag bit Device_ Provisioned and the actual operation of the Android database Sqlite3.
Writing is not easy, reprint need to indicate the source: http://blog.csdn.net/jscese/article/details/46506709 This article from the "Jscese" blog!
The application layer calls the static class static method of the setting class directly, and native needs to add it himself:
Add Support:
Added in Android.mk:
LOCAL_SHARED_LIBRARIES +=libsqlite
Copy Sqlite3 's own header file: external/sqlite/dist/sqlite3.h
Check operation:
Direct Paste Implementation code:
/*====================db==cmd============================*/#define provisioned_db_name "/data/data/com.android.providers.settings/databases/settings.db"#define query_device_provisioned_cmd "SELECT * from global where name= ' device_provisioned '"Static intCheckdeviceprovisioned () {Characvalue[Ten] = {' + '}; Sqlite3 * SDB =0;if(Sqlite3_open (Provisioned_db_name, &sdb)! = SQLITE_OK) {ERROR ("Open error!:%s\n", Sqlite3_errmsg (SDB));GotoError }if(Sqlite3_exec (SDB, Query_device_provisioned_cmd,"'' Loaddbinfo '"', &acvalue, NULL)! = SQLITE_OK) {ERROR ("Select provisioned error\n");GotoError }if(strcmp (Acvalue,"1") !=0) {ERROR ("device_provisioned =0:the device is not ready\n");GotoError } sqlite3_close (SDB); SDB =0;return 1; Error:sqlite3_close (SDB); SDB =0;return-1;}
Where Loaddbinfo is the callback function, &acvalue the array name passed in as the data carrier.
/*settings.db-global table-format:id|name| value*//*create TABLE Global (_id INTEGER PRIMARY KEY autoincrement,name text UNIQUE on CONFLICT replace,value TEXT); *//*now Get value*/intLoaddbinfo (void* Pbuffer,intIcolumnChar* * Pvalue,Char* * pname) { for(intIloop =0; Iloop < Icolumn; iloop++) {if((iloop==icolumn-1) && (pbuffer! =NULL) {strcpy (Char*) Pbuffer,pvalue[iloop]);//above char type array, type conversion} }return 0;}
Simple and convenient ~
Android NDK differentiates the first time starting-sqlite3 operation support