May crash when External-Media is not mounted. : Environment « Core Class « Android






May crash when External-Media is not mounted.

    
// Created by plusminus on 13:24:05 - 21.09.2008
//package org.andnav2.osm.util;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

class Util {
  public static final String DEBUGTAG = "OPENSTREETMAP";

  public static final String BASEPATH_ON_EXTERNAL_MEDIA = "andnav2/";

  public static final String SDCARD_SAVEDROUTES_PATH = "routes/";
  public static final String SDCARD_SAVEDTRACES_PATH = "traces/";
  public static final String SDCARD_SKYHOOKCACHE_PATH = "skyhookcache/";
  public static final String SDCARD_TILE_PATH = "tiles/";

  public static final int NOT_SET = Integer.MIN_VALUE;

  public static final int Y = 0;
  public static final int X = 1;
  /**
   * May crash when External-Media is not mounted.
   * @return path, like <code>"/sdcard/andnav2/"</code> always ending with a <code>"/"</code>
   */
  public static final String getAndNavExternalStoragePath(){
    final String absoluteExternalPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
    if(absoluteExternalPath.endsWith("/")) {
      return absoluteExternalPath + BASEPATH_ON_EXTERNAL_MEDIA;
    } else {
      return absoluteExternalPath + "/" + BASEPATH_ON_EXTERNAL_MEDIA;
    }
  }
}

   
    
    
    
  








Related examples in the same category

1.Create a new directory on external storage
2.is Storage Readable/Writable
3.Get External Storage Directory
4.Environment.MEDIA_MOUNTED, Environment.MEDIA_MOUNTED_READ_ONLY
5.Utility class used to deal with SD card cache.
6.return True if the external storage is available/writable.