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. 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 ");
C
# 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:
# Getprop persist. SYS. Language
# Setprop persist. SYS. Language ZH
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 we want to add a property: for example: silvan_liu
Path: System/CORE/rootdir/int. RC
Under the on post-FS-data directory
Setprop persist. SYS. silvan_liu 1 // persist. sys prefix name; 1 is the initial value
PS: different prefix names have different permissions, which are not described here; and why the on post-FS-data directory should be loaded, which 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 FinalString vivien_fastfood = "Hungry ";
1) The method is as follows:
@ Override
Public VoidOnresume ()
{
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;
____________________________________________________________________________________
From: http://blog.csdn.net/k1102k27/article/details/7106124
In Android source code development, some global labels or variables are often used. At this time, we can add the desired attributes to the Android system.
1. settings. System
This type of system attribute is often used. For example, when the flight mode is enabled or disabled, we change the value of settings. system. airplane_mode_on.
The following describes how to define a system attribute. For example, to add an attribute named "silvan_liu"
Path: frameworks/base/CORE/Java/Android/provider/settings. Java
[Java]View plaincopy
- Public static final string silvan_liu = "silvan_liu ";
- Public static final string [] settings_to_backup = {
- ~
- + Silvan_liu
- ~
- }
After this is added, you can use settings. system. getint (getcontentresolver (), settings. system. silvan_liu, 0) and settings. system. getint (getcontentresolver (), settings. system. silvan_liu, 0) to get and set the attribute value of silvan_liu.
2. systemproperties
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 we want to add a property: for example: silvan_liu
Path: System/CORE/rootdir/int. RC
Under the on post-FS-data directory
Setprop persist. SYS. silvan_liu 1 // persist. sys prefix name; 1 is the initial value
PS: the permissions for different prefix names are not described here; and the reason why the on post-FS-data directory should be loaded is related to the Int. RC syntax.
The above is the place where I used it in my actual project. I may not be very familiar with it. I still need to explore it.