最近项目(海思V600二次开发)有个需求,从U盘读取图片并将其替换成Logo,简单的讲分三步:
第一:查找u盘是否挂载并且获得U盘路径,代码如下:
public 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) {
// System.out.println(line);
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;
if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
dir = dir.concat(columns[1] );
break;
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
dir = dir.concat(columns[1]);
break;
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dir;
}
第二,从u盘查找是否存在bootlogo.jpg 文件,代码如下
public String getFile(String url)
{
String dir = "";
try
{
//System.out.println(url);
File[] files =new File(url).listFiles();
System.out.println(files.length);
for (int i =0; i < files.length; i++)
{
File f = files[i];
if(f.getName().equals("bootlogo.jpg"))// if(f.getPath().indexOf("bootlogo.jpg")>=0)
{
return f.getPath();
}
}
catch (Exception e)
{
Log.i("VideoPlayer", "not find file!") ;
}
return dir;
}
第三步,海思方案针对替换logo提供了底层命令,通过AsyncTask执行命令,代码如下 public void changeLogo()
{
Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec("sample_pdm 2 "+filePath);
}
catch (IOException e) {
e.printStackTrace();
}
}
通过上面三步既可以实现功能,但是有一点,通过adb mount 命令发现,u盘跟sdcard打印的信息一模一样,有没有大神可以告诉下怎么区分他们呢?