android执行外部命令、检测文件是否存在、自动检测U盘路径
private final String UDiskFileName = "/2969_logo/bootfile.image";
private final String LocalFile = "/tmp/factory/bootfile.image";
private boolean setBootLogo()
{
String tmp = getExternalStorageDirectory();
String USBPath = tmp.split("\n")[0];
if(USBPath.length() <= 0)
{
Toast.makeText(TSBPanelMode.this, "没有检测到U盘",
Toast.LENGTH_LONG).show();
return false;
}
String UDiskFile = USBPath + UDiskFileName;
Log.d("XYP_DEBUG", UDiskFile);
if (!fileIsExists(UDiskFile))
{
Toast.makeText(TSBPanelMode.this, "U盘中没有文件" + UDiskFileName,
Toast.LENGTH_LONG).show();
return false;
} try
{
String tmpcmd = "mount -o remount,rw /system ;\n"+
"rm " + LocalFile + "; \n" +
"cp " + UDiskFile + " " + LocalFile +";\n" +
"ls;\n";
String[] cmd = new String[] { "/bin/sh","-c", tmpcmd};
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(cmd);
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null)
{
Log.d(TAG, line);
}
mTvManager.saveFactoryData();
Log.d("XYP_DEBUG", "==== have done ====");
}catch(Exception e)
{
e.printStackTrace();
return false;
} if (!fileIsExists(LocalFile))
{
Toast.makeText(TSBPanelMode.this, "U盘中文件没有复制到本地存储空间",
Toast.LENGTH_LONG).show();
return false;
}
return true;
}
private boolean fileIsExists(String strFile)
{
try
{
File f=new File(strFile);
if(!f.exists())
{
return false;
}
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
public static String getExternalStorageDirectory(){
String dir = new String();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
if(columns[1].contains("emulated"))
continue;
dir = dir.concat(columns[1] + "\n");
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dir;
}
android执行外部命令、检测文件是否存在、自动检测U盘路径的更多相关文章
- golang os/exec 执行外部命令
exec包执行外部命令,它将os.StartProcess进行包装使得它更容易映射到stdin和stdout,并且利用pipe连接i/o. func LookPath(file string) (st ...
- PHP在linux上执行外部命令
PHP在linux上执行外部命令 一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以 ...
- Android执行shell命令
一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/bin/cat", &q ...
- Powershell 执行外部命令
Powershell 执行外部命令 724 11月, 2011 在 Powershell tagged Powershell教程 / 程序 by Mooser Lee本文索引[隐藏]1通过nets ...
- php -- PHP在linux上执行外部命令,system(),exec(),shell_exec()
目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍 在PHP中调用外部命令,有三种方法: 1. 调用专门函 ...
- php执行外部命令
php执行外部命令的不少,例如:exec.shell_exec.system.popen等.我特意的讲一下popen,它跟其他函数不太一样,其他函数执行一个命令后,会等待其返回后,再向下执行,而pop ...
- Android执行shell命令 top ps
Android执行shell命令 一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/ ...
- php在linux中执行外部命令
目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以用,1>调用专门函数. ...
- PHP执行外部命令【转】
PHP是完全支持外部命令的,但是出于安全考虑,一般很少使用. PHP提供共了3种方法调用外部命令: (1)调用执行外部命令函数(system(),exec(),passthru(),shell_exe ...
随机推荐
- mac 上面安装mysql-python
安装过程中一直报错: EnvironmentError: mysql_config not found 最终下面的方式解决: 58down voteaccepted +200 Ok, well, fi ...
- WildMagic 简单图元(一)
#include <Wm5WindowApplication3.h> #include <Wm5VisualEffectInstance.h> using namespace ...
- Android应用测试性能的工具Emmagee,导出文件格式问题分析
原文引用自:http://www.open-open.com/lib/view/open1367026451078.html Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资 ...
- Keyboard Test Utility v1.0.1.0 电脑键盘测试软件绿色版
软件名称: 电脑键盘测试软件绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win8 / Win7 / Vista / WinXP软件大小: 917KB图片预览: 软件简介:Keyboard ...
- Java多态(二)
public class ExtendsTest { public static void main(String[] args) { A a1 = new A(); A a2 = new B(); ...
- spring框架--IOC容器,依赖注入
思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action 多个 [维护成员变量] service 一个 [不需要维护公共变量] dao 一个 [不需要维护 ...
- Windows下为Python编译C扩展模块
工具:CodeBlocks 13.12 步骤 1 打开CodeBlocks新建工程:Shared library -- c -- sample [默认GUN GCC Compli ...
- [原]innerText与innerHTML区别
window.onload = function () { document.getElementById('btn1').onclick = function () { ...
- dialog弹出,点击back按键无法返回问题解决
今天阅读队友代码,调试代码中,发现对话框弹出点击back按键无法返回问题解决. 代码如下: /** * 单个按钮没有标题的弹框 * * @param context * @param content内 ...
- vi 操作技巧
输入模式的操作Home光标到行首End 光标到行尾Page Up和Page Down上下翻页Delect删除光标位置的字符 删除操作(命令模式使用)x删除光标处的单个字符dd删除光标所在行dw删除当前 ...