Android Framework Development Global System property set and get

Source: Internet
Author: User

Android command line/C language/java setting methods to get System properties

Set and get Systemproperty properties in Java:

Systemproperties.getint ("Persist.sys.boot_music_control", 0) systemproperties.set ("Persist.sys.boot_music_ Control "," "+value);

Get the property values set in the Java layer in C + +:

           Char Boot_music_control[property_value_max];            if (Property_get ("Persist.sys.boot_music_control", Boot_music_control, 0)! = 0) {                mediastatus = mediaplayer-> Setdatasource (Pbackupsoundfilename, NULL);            }

1 command line (shell) properties settings and get interface
2/C + + language properties settings and get interfaces
3 Java language Properties settings and acquired interfaces

Android provides a set of system parameter settings and access methods that can be set and retrieved statically or dynamically on the Android system using the Systemproperty class (which is used only in the framework or system-level applications). There is a large number of codes: Systemproperties.set ()/systemproperties.get (), which can read/set the properties of the system through these two interfaces, as the name implies, the system attributes, which are definitely shared across the whole system. Usually the execution of the program is independent of each other in process, how to realize global sharing?

What is the System Properties (Systemproperty detailed introduction and principle) and how is it implemented?

The property system is an important feature of Android. It runs as a service, managing system configuration and status. All of these configurations and states are attributes.

Each property is a key-value pair (Key/value pair) whose type is a string.

These properties may be the use state of some resources, the execution state of the process, the unique properties of the system ...
Command line (shell) properties settings and get interfaces

Getprop "Key"

SetProp "Key" "Value"

C + + language properties settings and get interfaces

The code is defined in:

SYSTEM/CORE/LIBCUTILS/PROPERTIES.C #define Property_key_max   32#define property_value_max,  int property_ Get (const char *key, char*value, const char *default_value), int property_set (const char *key, Constchar *value); int proper Ty_list (void (*PROPFN) (const char *key, Constchar *value, Void*cookie), void *cookie);   


#include "cutils/properties.h" char Prop[property_value_max] = "$"; if (Property_get ("Prop_name", prop, NULL)! = 0) {


Property_get returns the string length of the property value to which the value is get.
Prop_name is the property name.
Prop is the place where the property value string is stored.

Java language Properties settings and access to interfaces


<span style= "FONT-SIZE:14PX;"  >public static final int prop_name_max = 31;public static final int prop_value_max = 91;public static string Get (string Key), public static string get (String key, String def);p ublic static int getInt (String key,int def);p ublic Static Long Getlong (String Key,long def);p ublic static Boolean Getboolean (String key, Boolean def);p ublic static void set (String key , String val);p ublic static void Addchangecallback (Runnable callback);</span>

Problem solving:

1. Add switches in setting use the GetProperty () and SetProperty () properties to get and set properties, using the command line

ADB Shell Getprop

To view the value of the property:

[Persist.service.adb.enable]: [][persist.sys.ams.recover]: [False]<span style= "color: #FF0000;" >[persist.sys.boot_music_control]: [1]</span>[persist.sys.bootpackage]: [1][persist.sys.btn_auto_light] : [1]

2. The property value set in Build.prop is not obtained in C + +:

<span style= "color: #FF0000;" >persist.sys.boot_music_control</span>


                        Modfy by Jjli,control the boot and shutdown music char Boot_music_control[property_value_max];p roperty_get (" Persist.sys.boot_music_control ", Boot_music_control, 1); int boot_music_value = Atoi (Boot_music_control); if (boot_ Music_value = = 1) {mediastatus = Mediaplayer->setdatasource (Pbackupsoundfilename, NULL);

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: 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.