Manual operations on Android Databases

Source: Internet
Author: User

[First written by Steve Guo, please keep the mark if forwarding.]

Android saved settings in a database file which is/data/COM. Android. providers. Settings/databases/settings. DB. For some settings, Android does not
Support set them on the GUI. So we need find another way to set it. Here it is. I will use set "device_provisioned" as an example.

Android use sqlite3 as the database. So we can use sqlite3 to manage the database file.

ADB Shell

Sqlite3/data/COM. Android. providers. Settings/databases/settings. DB

Note: There are two sqlite3 instances. One is on the computer, which is located in Android-SDK-Windows \ tools \ sqlite3.exe, Which is used on the computer;

Another one is on the Android system (on the mobile phone), which is used for the Android system. For the latter, you need to enter the shell through the ADB shell.

The former is the window system, and the latter is the Linux system. Their file systems have different representation methods.

The above command will open the settings database. Then you will enter into sqlite3 command line.

First we can check how many tables existed in the database. Here lists the result.

SQLite>. Tables

Android_metadata bookmarks gservices

Bluetooth_devices favorites System

The settings we try to set lies in "system" table, so then we list all items in the table to view the current table information.

SQLite>. Dump System
Begin transaction;
Create Table System (_ id integer primary key autoincrement, Name text unique on conflict replace, value text );
Insert into "system" values (3, 'Volume _ system', '5 ');
Insert into "system" values (4, 'Volume _ voice ', '4 ');
Insert into "system" values (5, 'Volume _ alarm ', '6 ');
Insert into "system" values (6, 'mode _ ringer ', '2 ');
Insert into "system" values (7, 'vibrate _ on', '4 ');
Insert into "system" values (8, 'mode _ ringer_streams_affected', '6 ');
Insert into "system" values (9, 'execute _ streams_affected', '14 ');
Insert into "system" values (10, 'dim _ screen', '1 ');
Insert into "system" values (11, 'stay _ on_while_plugged_in ', '0 ');
Insert into "system" values (12, 'screen _ off_timeout ', '123 ');
Insert into "system" values (13, 'airplane _ mode_radios ', 'cell, Bluetooth, WiFi ');
Insert into "system" values (14, 'airplane _ mode_on ', '0 ');
Insert into "system" values (15, 'bluetooth _ on', '0 ');
Insert into "system" values (16, 'usb _ mass_storage_enabled ', '1 ');
Insert into "system" values (17, 'wifi _ on', '0 ');
Insert into "system" values (18, 'wifi _ networks_available_icationication_on ', '1 ');
Insert into "system" values (19, 'network _ preference ', '1 ');
Insert into "system" values (20, 'Auto _ time', '1 ');
Insert into "system" values (21, 'screen _ brightness ', '123 ');
Insert into "system" values (23, 'window _ animation_scale ', '1 ');
Insert into "system" values (24, 'transition _ animation_scale ', '0 ');
Insert into "system" values (26, 'Data _ roaming ', '0 ');
Insert into "system" values (27, 'date _ format', 'Mm-dd-yyyy ');
Insert into "system" values (30, 'device _ provisioned', '0 ');
Insert into "system" values (31, 'location _ providers_allowed ', 'GPS ');
Insert into "system" values (32, 'Install _ non_market_apps ', '1 ');
Insert into "system" values (119, 'ringtone', 'content: // media/external/Audio/Media/11 ');
Insert into "system" values (243, 'Volume _ Music', '15 ');
Insert into "system" values (244, 'Volume _ music_last_audible ', '15 ');
Insert into "system" values (266, 'Volume _ ring', '7 ');
Insert into "system" values (267, 'Volume _ ring_last_audible ', '7 ');
Insert into "system" values (274, 'font _ scale', '1. 0 ');
Insert into "system" values (275, 'adb _ enabled', '0 ');
Insert into "system" values (276, 'next _ alarm_formatted ','');
Create index systemindex1 on system (name );
Commit;

If we only want to view the content of the system table, we can simply use the SQL statement, for example:

Select * from system;

Note 1: sqlite3 supports two types of commands: SQL commands, non-SQL commands, and non-SQL commands prefixed with ".", such as the ". Tables" command.

Therefore, all statements not prefixed with "." are interpreted as SQL statements. At that time, you must add a semicolon (;) at the end of the SQL statement to indicate that the SQL statement input is complete,

The command you entered starts to be executed in the SQL language.

NOTE 2: sqlite3 commands can be viewed in the ". Help" language.

Pay attention to the first line about table information. the text marked with red will be used when writting SQL statements. assume we want to set "device_provisioned" to 1, we can simply type the following statement in the sqlite3
Console.

SQLite> Update "system" set value = '1' where name = 'device _ provisioned ';

You can enter ". Dump system" or select * from system; to check the modified value.

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.