判断是否有外置SD卡

private static String getDefaultPath(){
    boolean isHaveExternalSD = false;
    String DefaultPath = "/storage/sdcard0";
    File externalSDCard = new File("/storage/sdcard1");
    try {
        IMountService ms = getMs();
        isHaveExternalSD = ms.getVolumeState("/storage/sdcard1").equals(Environment.MEDIA_MOUNTED);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    if(isHaveExternalSD){
    DefaultPath = externalSDCard.toString();
    System.out.println("wangdandan1"+DefaultPath);
        }
    System.out.println("wangdandan"+DefaultPath);
    return DefaultPath;
    }

    private static IMountService getMs() {
        // TODO Auto-generated method stub
        IBinder service = ServiceManager.getService("mount");
        if (service != null) {
            return IMountService.Stub.asInterface(service);
        } else {
            System.out.println("Can't get mount service");
        }
        return null;
     }

posted @ 2014-05-08 18:25  plpdan  阅读(304)  评论(1编辑  收藏  举报