• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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);

 

posted on 2015-11-30 11:51  gisai  阅读(2838)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3