get System Property - Android App

Android examples for App:App Information

Description

get System Property

Demo Code


//package com.java2s;

import android.util.Log;

import java.lang.reflect.Method;

public class Main {
    private static boolean LOGENABLE = false;

    private static String getSystemProperty(String key, String defaultValue) {
        String value = defaultValue;
        try {//w ww.j av a 2 s  .com
            Class<?> clazz = Class.forName("android.os.SystemProperties");
            Method get = clazz.getMethod("get", String.class, String.class);
            value = (String) (get.invoke(clazz, key, ""));
        } catch (Exception e) {
            if (LOGENABLE) {
                Log.d("getSystemProperty", "key = " + key + ", error = "
                        + e.getMessage());
            }
        }

        if (LOGENABLE) {
            Log.d("getSystemProperty", key + " = " + value);
        }
        return value;
    }
}

Related Tutorials