Skip to content

Instantly share code, notes, and snippets.

@nasitra
Created October 31, 2015 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nasitra/bcc62b970e70301a3b05 to your computer and use it in GitHub Desktop.
Save nasitra/bcc62b970e70301a3b05 to your computer and use it in GitHub Desktop.
[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