android获取内置和外置SD卡路径


/**
   * 获取内置SD卡路径
   * @return
   */
  public String getInnerSDCardPath() {
    return Environment.getExternalStorageDirectory().getPath();
  }

  /**
   * 获取外置SD卡路径
   * @return	应该就一条记录或空
   */
  public List getExtSDCardPath()
  {
    List lResult = new ArrayList();
    try {
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec("mount");
      InputStream is = proc.getInputStream();
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);
      String line;
      while ((line = br.readLine()) != null) {
        if (line.contains("extSdCard"))
        {
          String [] arr = line.split(" ");
          String path = arr[1];
          File file = new File(path);
          if (file.isDirectory())
          {
            lResult.add(path);
          }
        }
      }
      isr.close();
    } catch (Exception e) {
    }
    return lResult;
  }
StringBuilder log = new StringBuilder();
    String inPath = getInnerSDCardPath();
    log.append("内置SD卡路径:" + inPath + "\r\n");

    List extPaths = getExtSDCardPath();
    int num=extPaths.size();
    for (int i=0;i<num;i++) {
      String path=extPaths.get(i).toString();
      log.append("外置SD卡路径:" + path + "\r\n");
    }
    System.out.println(log.toString());

   // String rasterPath = inPath+ "/raster/r.tif";
    String rasterPath = extPaths.get(0).toString()+ "/raster1/r.tif";
    FileRasterSource rasterSource=null;
    String TAG="闫磊";
    try {
      rasterSource = new FileRasterSource(rasterPath);
    } catch (IllegalArgumentException ie) {
      Log.d(TAG, "null or empty path");
    } catch (FileNotFoundException fe) {
      Log.d(TAG, "raster file:"+rasterPath+" doesn't exist");
    } catch (RuntimeException re) {
      Log.d(TAG, "raster file can't be opened");
    }
    Log.d(TAG,"加载影像:"+ rasterPath);
    RasterLayer rasterLayer = new RasterLayer(rasterSource);
    mMapView.addLayer(rasterLayer);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM