get Save Path on SD Card - Android android.os

Android examples for android.os:SD Card

Description

get Save Path on SD Card

Demo Code

import java.io.File;

import android.os.Environment;

public class Main {

  public static File getSavePath() {
    File path;/*from  w w w .ja v  a2  s  .c  om*/
    if (hasSDCard()) { // SD card
      path = new File(getSDCardPath() + "/remote/");
      path.mkdir();
    } else {
      path = Environment.getDataDirectory();
    }
    return path;
  }

  public static boolean hasSDCard() { 
    String status = Environment.getExternalStorageState();
    return status.equals(Environment.MEDIA_MOUNTED);
  }

  public static String getSDCardPath() {
    File path = Environment.getExternalStorageDirectory();
    return path.getAbsolutePath();
  }

}

Related Tutorials