我正在创建一个将以编程方式访问超级用户的应用程序。在这里我编写了一些代码,它将完美地执行命令,但我的应用程序将冻结并最终在一段时间后崩溃,请帮助我解决这个问题。这就是我所做的
public class MainActivity extends Activity {
Button files;
File path;
String directory_name;
EditText edit_text_files;
FileOutputStream fos;
String [] commands = new String[10];
boolean su;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
Process process = Runtime.getRuntime().exec("su");
DataOutputStream data_out = new DataOutputStream(process.getOutputStream());
DataInputStream data_in = new DataInputStream(process.getInputStream());
data_out.writeBytes("mkdir mnt/udisk/samplefolder"+"\n");
data_out.flush();
data_out.writeBytes("exit \n");
data_out.flush();
process.waitFor();
}
catch(Exception e)
{
Log.e("Commands Exception :", "executing commands exception");
}