android 查找u盘路径

本文介绍了在Android系统中如何检测U盘是否已挂载,并获取其路径,以实现从U盘读取图片进行替换Logo的操作。内容涉及到海思V600平台的二次开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     最近项目(海思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打印的信息一模一样,有没有大神可以告诉下怎么区分他们呢?



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值