Android调用系统自带的文件管理器进行文件选择

时间:2014-05-12 06:24:07   收藏:0   阅读:541

http://blog.csdn.net/zqchn/article/details/8770913的补充

FileUtils文件

public class FileUtils {
    public static String getPath(Context context, Uri uri) {
 
        if ("content".equalsIgnoreCase(uri.getScheme())) {
            String[] projection = { "_data" };
            Cursor cursor = null;
 
            try {
                cursor = context.getContentResolver().query(uri, projection,null, null, null);
                int column_index = cursor.getColumnIndexOrThrow("_data");
                if (cursor.moveToFirst()) {
                    return cursor.getString(column_index);
                }
            } catch (Exception e) {
                // Eat it
            }
        }
 
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }
 
        return null;
    }
}

Android调用系统自带的文件管理器进行文件选择,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!