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盘路径的更多相关文章

  1. golang os/exec 执行外部命令

    exec包执行外部命令,它将os.StartProcess进行包装使得它更容易映射到stdin和stdout,并且利用pipe连接i/o. func LookPath(file string) (st ...

  2. PHP在linux上执行外部命令

    PHP在linux上执行外部命令 一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以 ...

  3. Android执行shell命令

    一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/bin/cat", &q ...

  4. Powershell 执行外部命令

    Powershell 执行外部命令 724 11月, 2011  在 Powershell  tagged Powershell教程 / 程序 by Mooser Lee本文索引[隐藏]1通过nets ...

  5. php -- PHP在linux上执行外部命令,system(),exec(),shell_exec()

    目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍 在PHP中调用外部命令,有三种方法: 1. 调用专门函 ...

  6. php执行外部命令

    php执行外部命令的不少,例如:exec.shell_exec.system.popen等.我特意的讲一下popen,它跟其他函数不太一样,其他函数执行一个命令后,会等待其返回后,再向下执行,而pop ...

  7. Android执行shell命令 top ps

    Android执行shell命令 一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/ ...

  8. php在linux中执行外部命令

    目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以用,1>调用专门函数. ...

  9. PHP执行外部命令【转】

    PHP是完全支持外部命令的,但是出于安全考虑,一般很少使用. PHP提供共了3种方法调用外部命令: (1)调用执行外部命令函数(system(),exec(),passthru(),shell_exe ...

随机推荐

  1. rabbitmq(1)-入门

    参考: documentation: https://www.rabbitmq.com/documentation.htmldemo: https://www.rabbitmq.com/getstar ...

  2. 一步一步学EF系列 【7、结合IOC ,Repository,UnitOfWork来完成框架的搭建】

    前言 距离上一篇已经有段时间了,最近这段时间赶上新项目开发,一直没有时间来写.之前的几篇文章,主要把EF的基础都讲了一遍,这批文章就来个实战篇. 个人在学习过程中参考博客: Entity Framew ...

  3. 客户端登录验证 -- ESFramework 4.0 快速上手(15)

    在之前版本的Rapid引擎中,是没有提供客户端登陆验证的机制的,如果要验证用户的帐号密码信息,我们只有自己手动通过自定义信息来实现.在2011.04.25发布的新版本中,客户端Rapid引擎,则内置了 ...

  4. 使用freerdp远程连接Windows桌面

    之前使用的是rdesktop,但是由于其不支持NLA认证,便不能登录公司的电脑.为此,现在使用freerdp——这是package的名字,实际的可执行程序是xfreerdp.使用如下的命令行即可实现远 ...

  5. hadoop---wordcount命令

    [zznu@master file]$ hadoop jar ~/hadoop-2.5.2/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.2 ...

  6. apicloud ios 打包流程

    1创建APP ID 等 2创建pruduction创建证书,用 这个证书导出P12格式的.. 3profile 证书,选 APP STORE  AD-HOC ok... http://docs.api ...

  7. python3 随机数

    random库 random.random()返回n,则 0 <= n < 1的小数. random.uniform(a,b)    返回n ,则 a <= n <= b的浮点 ...

  8. bootstrap validator html attributes 选项

    常用的html属性:data-fv-message="The username is not valid"data-fv-notempty="true"data ...

  9. python_变量的命名规则

    python 变量的命名规则: 1. 要具有描述性 2.变量名只能由 数字,字母 ,下划线 组成,不可以是空格或者特殊字符(#!%……&) 3.不能以数字开头 4.保留字符不可用(print ...

  10. 十二、oracle 数据库(表)的逻辑备份与恢复

    一.介绍逻辑备份是指使用工具export将数据对象的结构和数据导出到文件的过程.逻辑恢复是指当数据库对象被误操作而损坏后使用工具import利用备份的文件把数据对象导入到数据库的过程.物理备份即可在数 ...