Add System Properties for Android: settings. System and systemproperties

Source: Internet
Author: User
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

 
  1. Public static final string silvan_liu = "silvan_liu ";
  2. Public static final string [] settings_to_backup = {
  3. ~
  4. + Silvan_liu
  5. ~
  6. }

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.

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.