Android NDK differentiates the first time starting-sqlite3 operation support

Source: Internet
Author: User

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

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.