यह स्निपेट रूट पहुँच की आवश्यकता है, लेकिन एक शेल कमांड
void execCommandLine(String command)
{
Runtime runtime = Runtime.getRuntime();
Process proc = null;
OutputStreamWriter osw = null;
try
{
proc = runtime.exec("su");
osw = new OutputStreamWriter(proc.getOutputStream());
osw.write(command);
osw.flush();
osw.close();
}
catch (IOException ex)
{
Log.e("execCommandLine()", "Command resulted in an IO Exception: " + command);
return;
}
finally
{
if (osw != null)
{
try
{
osw.close();
}
catch (IOException e){}
}
}
try
{
proc.waitFor();
}
catch (InterruptedException e){}
if (proc.exitValue() != 0)
{
Log.e("execCommandLine()", "Command returned error: " + command + "\n Exit code: " + proc.exitValue());
}
}
स्रोत
2010-09-27 21:10:21
आप बहुत बहुत धन्यवाद ... क्या इसे एक से अधिक खोल आदेशों को चलाने के लिए संशोधित करने के लिए की आवश्यकता होगी के रूप में दिया स्ट्रिंग निष्पादित करेंगे? –
सबसे खराब स्थिति आप प्रत्येक कमांड के लिए इस फ़ंक्शन को कॉल कर सकते हैं, लेकिन आप प्रत्येक कमांड को न्यूलाइन कैरेक्टर से अलग करने में सक्षम होना चाहिए \ n –