当前位置:编程学习 > wap >>

android 多个SD卡检测

手机中有多个SD卡,程序能检测SD卡个数码? 能获取他们的路径,容量信息吗?程序能选择任一SD卡作为存储路径吗? --------------------编程问答-------------------- MountService有对应的接口。查询SD的个数,对应获取名字等信息。 --------------------编程问答-------------------- 解决 
       StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE);
        try
        {
            String[] paths = (String[]) sm.getClass().getMethod("getVolumePaths", null).invoke(sm, null);
            for(int i = 0; i < paths.length; i++)
            {
                Log.i("iii", paths[i]);
                String status = (String) sm.getClass().getMethod("getVolumeState", String.class).invoke(sm, paths[i]);
                if(status.equals(android.os.Environment.MEDIA_MOUNTED))
                {
                    String txt = "测试成功.txt";
                    String sPath = paths[i] + File.separator + txt;
                    File file = new File(sPath);
                    if(file.exists())
                    {
                        file.delete();
                    }
                    try
                    {
                        file.createNewFile();
                    }
                    catch (IOException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }     
        } --------------------编程问答-------------------- mark 一下 谢谢楼主分享!~
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,