这是我正在使用的以下代码
try {
Runtime rnTm=Runtime.getRuntime();
Process execLang = rnTm.exec(new String[]{"getprop", "persist.sys.language"});
mCurrLocale = new BufferedReader(new InputStreamReader (execLang.getInputStream())).readLine();
execLang.destroy();
Process execCountry = rnTm.exec(new String[]{"getprop", "persist.sys.country"});
mCurrCountry = new BufferedReader(new InputStreamReader (execCountry.getInputStream())).readLine();
execLang.destroy();
Log.e("", "Device locale: "+mCurrLocale+" Co:"+mCurrCountry);
} catch (IOException e) {
e.printStackTrace();
return;
}
catch (SecurityException se) {
se.printStackTrace();
return;
}
It's working fine some phones and tablet.
但有时它会导致我的应用程序冻结并在 logcat 中给出以下结果。
I/System ( 1511): Failed to destroy process 1547
I/System ( 1511): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
I/System ( 1511): at libcore.io.Posix.kill(Native Method)
I/System ( 1511): at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
I/System ( 1511): at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:257)