Get filename and path from uri from mediastore
来源:互联网 发布:科技软件 编辑:程序博客网 时间:2024/06/03 20:18
I have an onActivityResult returning from an mediastore image selection which I can get a URI for an image using the following: Uri selectedImage = data.getData();
Converting this to a string gives this:content://media/external/images/media/47 Or to a path gives:/external/images/media/47 However I can't seem to find a way to convert this into an absolute path, as I want to load the image into a bitmap without having to copy it somewhere. I know this can be done using the URI and content resolver but this seems to break on rebooting of the phone, I guess MediaStore doesn't keep its numbering the same between reboots.
public String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try { String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } }}
0 0
- Get filename and path from uri from mediastore
- Get filename and path from URI from mediastore
- get filename from path without _splitpath
- Use regular expression to get filename from a file full path name.
- A way to get filename from batch
- Kernel: Get filename from "struct file *"
- get current user and user profile path from window service
- Get real path from URI, Android KitKat new storage access framework
- Get the webpage data from URI.
- jQuery: Get filename from input [type='file']
- Get phone and email from page
- Get image from URL and save it
- get select text and value from dropdownlist
- [asp.net] Get variables from POST and GET request
- Removing the trailing file name and backslash from a path
- path.resolve([from ...], to)
- Get CellId and other Imformation from mobile phones via J2ME
- how to get preloader and dsp_bl from mtk phone?
- 验证图片生成详细简解
- 这几天面试的一些体会吧
- 如何判断Apache服务器的工作模式
- 第一届文思在线编程大赛题解析。
- linux简单命令(继续更新中)
- Get filename and path from uri from mediastore
- php 并发时库存减少至小于0的解决方案
- GFX::3d::engine-加载obj
- WCF技术剖析之八:ClientBase<T>中对ChannelFactory<T>的缓存机制
- Swing ——Swing基本结构
- 1072:找规律填数字
- dclusr.dll
- EBS开发附件上传和下载功能
- Ubuntu Linux 环境变量PATH设置