zoukankan      html  css  js  c++  java
  • 怎么SDCard上的获取相册照片

    [java] view plain copy
     
    1. private String getRealPathFromURI(Uri contentUri) {  
    2.         Cursor cursor = null;  
    3.         String result = contentUri.toString();  
    4.         String[] proj = {MediaStore.Images.Media.DATA};  
    5.         cursor = managedQuery(contentUri, proj, null, null, null);  
    6.         if(cursor == null) throw new NullPointerException("reader file field");  
    7.         if (cursor != null) {  
    8.             int column_index = cursor  
    9.                     .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);  
    10.             cursor.moveToFirst();  
    11.             // 最后根据索引值获取图片路径  
    12.             result = cursor.getString(column_index);  
    13.              try    
    14.                 {    
    15.                     //4.0以上的版本会自动关闭 (4.0--14;; 4.0.3--15)    
    16.                     if(Integer.parseInt(Build.VERSION.SDK) < 14)    
    17.                     {    
    18.                         cursor.close();    
    19.                     }    
    20.                 }catch(Exception e)    
    21.                 {    
    22.                     Log.e(TAG, "error:" + e);    
    23.                 }    
    24.         }  
    25.         return result;  
    26.     }  

    //path = path.substring(path.indexOf("/sdcard"), path.length());  目录不要写死 。

  • 相关阅读:
    centos 用户管理
    rsync 实验
    文件共享和传输
    PAT 1109 Group Photo
    PAT 1108 Finding Average
    PAT 1107 Social Clusters
    PAT 1106 Lowest Price in Supply Chain
    PAT 1105 Spiral Matrix
    PAT 1104 Sum of Number Segments
    PAT 1103 Integer Factorization
  • 原文地址:https://www.cnblogs.com/exmyth/p/5411721.html
Copyright © 2011-2022 走看看