FileDocCategorySizeDatePackage
SystemProperties.javaAPI DocAndroid 1.5 API5187Wed May 06 22:41:56 BST 2009android.os

SystemProperties

public class SystemProperties extends Object
Gives access to the system properties store. The system properties store contains a list of string key-value pairs. {@hide}

Fields Summary
public static final int
PROP_NAME_MAX
public static final int
PROP_VALUE_MAX
Constructors Summary
Methods Summary
public static java.lang.Stringget(java.lang.String key)
Get the value for the given key.

return
an empty string if the key isn't found
throws
IllegalArgumentException if the key exceeds 32 characters


         
           
           

                                 
         
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get(key);
    
public static java.lang.Stringget(java.lang.String key, java.lang.String def)
Get the value for the given key.

return
if the key isn't found, return def if it isn't null, or an empty string otherwise
throws
IllegalArgumentException if the key exceeds 32 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get(key, def);
    
public static booleangetBoolean(java.lang.String key, boolean def)
Get the value for the given key, returned as a boolean. Values 'n', 'no', '0', 'false' or 'off' are considered false. Values 'y', 'yes', '1', 'true' or 'on' are considered true. (case insensitive). If the key does not exist, or has any other value, then the default result is returned.

param
key the key to lookup
param
def a default value to return
return
the key parsed as a boolean, or def if the key isn't found or is not able to be parsed as a boolean.
throws
IllegalArgumentException if the key exceeds 32 characters

        String value = get(key);
        // Deal with these quick cases first: not found, 0 and 1
        if (value.equals("")) {
            return def;
        } else if (value.equals("0")) {
            return false;
        } else if (value.equals("1")) {
            return true;
        // now for slower (and hopefully less common) cases
        } else if (value.equalsIgnoreCase("n") ||
                   value.equalsIgnoreCase("no") ||
                   value.equalsIgnoreCase("false") ||
                   value.equalsIgnoreCase("off")) {
            return false;
        } else if (value.equalsIgnoreCase("y") ||
                   value.equalsIgnoreCase("yes") ||
                   value.equalsIgnoreCase("true") ||
                   value.equalsIgnoreCase("on")) {
            return true;
        }
        return def;
    
public static intgetInt(java.lang.String key, int def)
Get the value for the given key, and return as an integer.

param
key the key to lookup
param
def a default value to return
return
the key parsed as an integer, or def if the key isn't found or cannot be parsed
throws
IllegalArgumentException if the key exceeds 32 characters

        try {
            return Integer.parseInt(get(key));
        } catch (NumberFormatException e) {
            return def;
        }
    
public static longgetLong(java.lang.String key, long def)
Get the value for the given key, and return as a long.

param
key the key to lookup
param
def a default value to return
return
the key parsed as a long, or def if the key isn't found or cannot be parsed
throws
IllegalArgumentException if the key exceeds 32 characters

        try {
            return Long.parseLong(get(key));
        } catch (NumberFormatException e) {
            return def;
        }
    
private static native java.lang.Stringnative_get(java.lang.String key)

private static native java.lang.Stringnative_get(java.lang.String key, java.lang.String def)

private static native voidnative_set(java.lang.String key, java.lang.String def)

public static voidset(java.lang.String key, java.lang.String val)
Set the value for the given key.

throws
IllegalArgumentException if the key exceeds 32 characters
throws
IllegalArgumentException if the value exceeds 92 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (val != null && val.length() > PROP_VALUE_MAX) {
            throw new IllegalArgumentException("val.length > " +
                PROP_VALUE_MAX);
        }
        native_set(key, val);