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 ...
随机推荐
- JS学习之路,之弹性运动框架
弹性运动:顾名思义,就如同物理中的加速减速运动,当开始时速度过大,到达终点时,速度不会立刻停下,而是再前进一段距离,而后再向相反方向运动,如此往复. var timer=null; var speed ...
- SignalR的坑爹细节
好吧!SignalR的确是好用,照着官网的例子自己敲了一遍,死活得不到效果... 检查了半天,抱着试一试的心态吧原来在服务端大写开头的Hub类和大写开头的方法在客户端调用的时候,全部改成小写,一刷新, ...
- hdu 1859 最小长方形
Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. Input ...
- OC之消息基本概念
要说清楚消息这个话题,我们必须先来了解三个概念 Class, SEL, IMP,它们在 objc/objc.h 中定义: typedef struct objc_class *Class; typed ...
- poj1256(全排列stl)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;bool cmp ...
- 重拾Ruby—新的征程
作家格拉德威尔在<异类>一书中指出: “人们眼中的天才之所以卓越非凡,并非天资超人一等,而是付出了持续不断的努力.1万小时的锤炼是任何人从平凡变成超凡的必要条件.“ 他将此称为“一万小时定 ...
- MySQL-MHA高可用方案
http://files.cnblogs.com/jimingsong/mha-mysql.pdf 此方案为一号店MySQL MHA高可用方案.备注.
- 写一个CGI程序并运行
准备Linux和Apache我在/var/www/cgi-bin/下建一个文件get.c #include <stdio.h> #include <stdlib.h> int ...
- 正则表达式:reg.test is not a function
正则中 比如 var reg = "/^[0-9]$/" 会报 reg.test is not a function 如果 var reg = /^[0-9]$/ 就不会有错 因为 ...
- 单击Echart饼图实现数据钻取
使用场景和需求: 第一层饼图显示党员党龄分布的情况. 点击某个党龄段,查看拥有该党龄段的党支部. 默认显示3个党支部,余下的党支部合并为其它,点击其它,查看余下的党支部. 点击某个党支部,返回第一层饼 ...