How to get the build.prop values?

后端 未结 8 865
梦谈多话
梦谈多话 2021-01-06 07:03

How do I get the build.prop values that are found in /system/build.prop without root access? How do I edit them?

相关标签:
8条回答
  • 2021-01-06 07:17

    use android.os.Build class, see http://developer.android.com/reference/android/os/Build.html, but you can not edit it without root access.

    0 讨论(0)
  • 2021-01-06 07:18

    Does System.getProperty() help? As an alternative, you can execute getprop in a Process and retrieve its output.

    0 讨论(0)
  • 2021-01-06 07:34

    Such as: SystemProperties.get("ro.rksdk.version")

    0 讨论(0)
  • 2021-01-06 07:37

    Try This

    static String GetFromBuildProp(String PropKey) {
        Process p;
        String propvalue = "";
        try {
            p = new ProcessBuilder("/system/bin/getprop", PropKey).redirectErrorStream(true).start();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                propvalue = line;
            }
            p.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return propvalue;
    }
    
    0 讨论(0)
  • 2021-01-06 07:37

    I have checked multiple devices including some Samsung and LG devices as well as a Nexus 4, latest one was the Nvidia Shield Tablet with Android 6.0. On all devices ll on /system/build.prop gave me this result(of course with varying size and date of build.prop):

    -rw-r--r-- root root 3069 2015-10-13 21:48 build.prop

    This means that anyone and any app without any permissions can read the file. Root would only be required for writing the non "ro."-values. You could just create a new BufferedReader(new FileReader("/system/build.prop")) and read all lines.

    Advantages of this approach:

    • no need for reflection (SystemProperties.get)
    • no need to spawn a Process and executing getprop

    Disadvantages:

    • does not contain all system properties (some values e.g. are set at boot only available at runtime)
    • not handy for getting a specific value compared to SystemProperties.get
    0 讨论(0)
  • 2021-01-06 07:39

    You can probably consider using SystemProperties.get("someKey") as suggested by @kangear in your application using reflection like:

    public String getSystemProperty(String key) {
        String value = null;
    
        try {
            value = (String) Class.forName("android.os.SystemProperties")
                    .getMethod("get", String.class).invoke(null, key);
        } catch (Exception e) {
          e.printStackTrace();
        }
    
        return value;
    }
    

    And then you can use it any where like:

    getSystemProperty("someKey");
    
    0 讨论(0)
提交回复
热议问题