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());  目录不要写死 。

  • 相关阅读:
    通过GetProcAddress函数动态调用dll中地函数,是否必须通过extern C声明导出函数?
    函数指针与typedef
    MSDN DLL 综合
    DLL
    Firefox浏览器兼容Javascript脚本的方法
    C++中extern “C”含义深层探索
    生成索引脚本
    使用Go语句生成数值表
    避免使用count(*)获得表的记录数,解决其延迟问题
    在程序开发中怎样写SQL语句可以提高数据库的性能
  • 原文地址:https://www.cnblogs.com/exmyth/p/5411721.html
Copyright © 2011-2022 走看看