Example usage for android.os Environment getExternalStorageDirectory

List of usage examples for android.os Environment getExternalStorageDirectory

Introduction

In this page you can find the example usage for android.os Environment getExternalStorageDirectory.

Prototype

public static File getExternalStorageDirectory() 

Source Link

Document

Return the primary shared/external storage directory.

Usage

From source file:Main.java

public static void allScan(Context context) {
    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}

From source file:Main.java

public static String RenameFileToNewPath(String oldpath) {
    String path = oldpath;//from www. j  a va2  s  .com
    path = path.replace("/mnt/sdcard/", "");
    String new_path = path.replace(".ck", "");
    File sdcard = Environment.getExternalStorageDirectory();
    File from = new File(sdcard, oldpath);
    File to = new File(sdcard, new_path);
    from.renameTo(to);
    return to.toString();
}

From source file:Main.java

static String getSaveLocation(String saveName) {
    String saveLocation;/*from   w w w  .  jav  a 2s.  c  o  m*/
    File notification = new File(
            Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + saveName + ".txt");

    try {
        BufferedReader br = new BufferedReader(new FileReader(notification));

        saveLocation = br.readLine();
        saveLocation = saveLocation.replace("file://", "").replaceAll(" ", "%20");
        br.close();
    } catch (Throwable t) {
        saveLocation = "Instagram";
    }

    if (!saveLocation.substring(saveLocation.length() - 1).equals("/") && !saveLocation.equals("Instagram")) {
        saveLocation = saveLocation + "/";
    }

    return saveLocation;
}

From source file:Main.java

public static String getSdCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        java.io.File fExternalStorageDirectory = Environment.getExternalStorageDirectory();
        java.io.File autonaviDir = new java.io.File(fExternalStorageDirectory, "amapsdk");
        boolean result = false;
        if (!autonaviDir.exists()) {
            result = autonaviDir.mkdir();
        }//  ww  w.  j  av  a  2 s.c  om
        java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap");
        if (!minimapDir.exists()) {
            result = minimapDir.mkdir();
        }
        return minimapDir.toString() + "/";
    } else {
        return "";
    }
}

From source file:Main.java

public static void WriteStringToSD(String fileName, String content) {
    Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    File file = new File(Environment.getExternalStorageDirectory(), fileName);
    try {/*from  www . ja v  a2 s .  c  om*/
        FileOutputStream fos = new FileOutputStream(file, true);
        fos.write(content.getBytes());
        fos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static File getAlbumFolder(String albumName) {
    File folder = new File(Environment.getExternalStorageDirectory() + File.separator + albumName);
    if (!folder.exists()) {
        folder.mkdir();/*  w  ww  . java  2s  . co m*/
        try {
            new File(folder, ".yesmedia").createNewFile();
        } catch (Exception e) {
            Log.d(TAG, "[AirImagePickerUtils] exception = " + e.getMessage());
            Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)");
            return null;
        }
    }
    return folder;
}

From source file:Main.java

public static String getExternalStoragePath() {
    File externalStorageDirectory = null;

    if (isExternalStorageExists()) {
        externalStorageDirectory = Environment.getExternalStorageDirectory();
    }/*ww w .jav  a2s  . c o m*/
    return (externalStorageDirectory != null) ? externalStorageDirectory.getAbsolutePath() : null;
}

From source file:Main.java

public static String getSDcardDir() {
    return Environment.getExternalStorageDirectory().getPath() + "/";
}

From source file:Main.java

public static String dataRootDirectory(int extNum) {
    File sdcard = Environment.getExternalStorageDirectory();
    if (!sdcard.exists()) {
        sdcard = new File("/sdcard");
    }// w w  w  .  j a  v a 2  s .  co m
    if (sdcard.exists()) {
        File rd = new File(sdcard, "YaoTouWan");
        if (extNum > 0) {
            rd = new File(rd.getAbsolutePath() + extNum);
        }
        if (!rd.exists()) {
            if (rd.mkdirs()) {
                return rd.getAbsolutePath();
            }
        } else if (rd.isDirectory()) {
            return rd.getAbsolutePath();
        } else {
            return dataRootDirectory(extNum + 1);
        }
    } else {
        // todo no /sdcard/
        return null;
    }
    return sdcard.getAbsolutePath();
}

From source file:Main.java

public static String getSDPath() {
    File SDdir = null;//w  w  w .  ja  v a2 s.  co m
    boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        SDdir = Environment.getExternalStorageDirectory();
    }
    if (SDdir != null) {
        return SDdir.toString();
    } else {
        return null;
    }
}