Skip to content

Instantly share code, notes, and snippets.

@E3V3A E3V3A/getprop.java forked from nasitra/getprop.java
Created Jan 11, 2017

Embed
What would you like to do?
[android] getprop from Java
// ref: https://groups.google.com/forum/#!topic/android-developers/M-g3LqIY_xM
private String getProperty(String name, String defaultValue) {
ArrayList<String> processList = new ArrayList<String>();
String line;
Pattern pattern = Pattern.compile("\\[(.+)\\]: \\[(.+)\\]");
Matcher m;
try {
Process p = Runtime.getRuntime().exec("getprop");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
processList.add(line);
m = pattern.matcher(line);
if (m.find()) {
MatchResult result = m.toMatchResult();
if(result.group(1).equals(name))
return result.group(2);
}
}
input.close();
} catch (Exception err) {
err.printStackTrace();
}
return defaultValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.