Created
October 31, 2015 02:41
-
-
Save nasitra/bcc62b970e70301a3b05 to your computer and use it in GitHub Desktop.
[android] getprop from Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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