Hal (C ++)
Property_get
Property_set
Framework and app (Java)
Systemproperties. Get
Systempropertise. Set
========================================================== ========================================================== ========================================================== ==============
Systemproperties and settings. System
1 use systemproperties. Get
If the attribute name starts with "Ro.", this attribute is regarded as a read-only attribute. Once set, the attribute value cannot be changed.
If the attribute name starts with "Persist.", when this attribute is set, its value will also be written to/data/property.
To view the current language settings, type:
Getprop persist. SYS. Language
The current language settings are displayed:
If you need to set the current language:
Setprop persist. SYS. Language ZH
Or
Setprop persist. SYS. Language en
In C ++, the two functions corresponding to Java are property_set and property_get. In fact, Java calls these two functions through JNI.
The Java code is as follows:
Import Android. OS. systemproperties;
Systemproperties. Set ("Persist. SYS. Language", zone. GETID ());
String lang = systemproperties. Get ("Persist. SYS. Language ");
Method:
Boolean fastfoodenable = systemproperties. getboolean ("Persist. SYS. fastfoodenable", false );
Setting method:
Systemproperties. Set ("Persist. SYS. fastfoodenable", "true ");
The C code is as follows:
# Include <cutils/properties. h>
Property_set ("Persist. SYS. Language", "ZH ");
Property_get ("Persist. SYS. Language", proplang, "en ");
In the ADB shell, you can read and modify the following name:
Setprop persist. SYS. Language ZH
Or
Setprop persist. SYS. Language en
Create and modify Android Properties Using systemproperties. set (name, value) to obtain the android attributes using systemproperties. get (name), note that the name of the android attribute has certain format requirements, as follows: the prefix must be defined in System \ core \ init \ property_service.c, the program that sets System Properties must also have system or root permissions.
If you want to add a property, for example, voice_ctrl
Path: System/CORE/rootdir/int. RC
Under the on post-FS-data directory
Setprop persist. SYS. voice_ctrl 1 // persist. sys prefix name; 1 is the initial value
Different prefix names have different permissions. Why should I load the on post-FS-data directory? This is related to the Int. RC syntax.
2. Use settings. system. putint
In this way, the variables are saved to the settings database, and the flight mode switch is implemented in this way.
First, you need to define a system property value.
Path: frameworks/base/CORE/Java/Android/provider/settings. Java
Public static final string vivien_fastfood = "Hungry ";
1) The method is as follows:
@ Override
Public void onresume ()
{
Super. onresume ();
If (settings. system.Getint(Getcontentresolver (), settings. system. vivien_fastfood, 0) = 1)
{
Myesorno. setchecked (true );
}
Else
Myesorno. setchecked (false );
}
2) settings
If (myesorno. ischecked ()){
Settings. system.Putint(Getcontentresolver (),
Settings. system. vivien_fastfood, 1 );
} Else {
Settings. system.Putint(Getcontentresolver (),
Settings. system.Vivien_fastfood, 0 );
}
Import Android. provider. settings;