我尝试访问我的文件夹在SD卡并安装myapp.apk,我用这个code:
I try to access to my folder in sdcard and install myapp.apk, i use this code:
Runtime.getRuntime().exec("cd sdcard/.yasmin");
Runtime.getRuntime().exec("adb install tefli.apk");
但可惜的是,我有这个错误:
But unfortunatelly i have this error:
05-11 11:09:57.925: WARN/System.err(1399): java.io.IOException:
Error running exec(). Commands: [cd, sdcard/.yasmin] Working Directory: null Environment: null
请任何人有一个想法。 在此先感谢。
Anybody please have an idea. thanks in advance.
我不知道,这将解决您的问题,但AFAIK,每次调用 EXEC()
创建一个新的外壳。一个可能的解决方案是做到以下几点:
I am not sure that this will fix your problem, but AFAIK, each call to exec()
creates a new shell. A possible solution is to do the following:
进程p =调用Runtime.getRuntime()EXEC(...)
使用 p.getInputStream()抓斗的过程中的InputStream;
运行第二个命令。
Get the process of the exec() using: Process p = Runtime.getRuntime().exec(...)
.
Grab the process inputStream using p.getInputStream();
.
Run the second command.
也注意到,您试图访问的SD卡作为你的根文件夹,并在硬codeD路径,考虑以下几点:
also note that you are trying to access the sdcard as you were in root folder and in a hardcoded path, consider the following:
Process p = Runtime.getRuntime().exec("cd /sdcard/.yasmin");
甚至更好:
Process p = Runtime.getRuntime().exec("cd " + Environment.getExternalStorageDirectory() + "/.yasmin");
希望能对大家有所帮助!
Hope it'll help!