由DocumentsUI 得到文件path
来源:互联网 发布:软件界面素材下载 编辑:程序博客网 时间:2024/05/21 07:11
uriForCapture = content://com.android.providers.media.documents/document/video%3A98
uriForCapture = content://media/external/video/media/98
针对这2中uri第二种通过查多媒体数据库很容易得到文件path,类似:uriString = /storage/emulated/0/DCIM/Camera/***.mp4
但是第一种不能直接查询到。
可以尝试以下方法:
private String getPathFromDocmentsUri(Context ctx,Uri docUri) {
String imagePath = null;
if (DocumentsContract.isDocumentUri(ctx, docUri)) {
String docId = DocumentsContract.getDocumentId(docUri);
if ("com.android.externalstorage.documents".equals(docUri.getAuthority())) {
String dir = docId.split(":")[0];
String selec= docId.split(":")[1];
imagePath = "/storage/"+dir+"/"+selec;
return imagePath;
}else if ("com.android.providers.media.documents".equals(docUri.getAuthority())) {
String id = docId.split(":")[1];
//String selection = MediaStore.Video.Media._ID + "=" + id;
imagePath = getPathFromDoc(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString()+"/"+id);
} else if ("com.android.providers.downloads.documents".equals(docUri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
Long.valueOf(docId));
imagePath = getPathFromDoc(contentUri.toString());
}
}
return imagePath;
}
private String getPathFromDoc(String docUri) {
String imagePath = null;
Log.d(TAG, "getPathFromDoc ,imageUrl= " + docUri);
Uri uri = Uri.parse(docUri);
String[] proj = { MediaStore.Images.Media.DATA };
Cursor imageCursor = mContext.getContentResolver().query(uri, proj, null, null, null);
if (imageCursor != null) {
if (imageCursor.moveToFirst()) {
int image_column_index = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
imagePath = imageCursor.getString(image_column_index);
}
imageCursor.close();
}
return imagePath;
}
- 由DocumentsUI 得到文件path
- android4.4的文件管理器documentsui源码解析
- android4.4的文件管理器documentsui源码解析
- 由文件描述符得到文件的全路径
- 由句柄得到文件名
- 由域名得到ip
- 由GA得到的
- 由图片得到异形窗体
- 由PID得到进程名
- 由packagename得到应用程序信息
- 由跑步得到的启示
- osgearth由经纬度得到高程
- 根据图片在IE中的URL得到图片文件在本地磁盘中的Path
- JSTL中得到context path
- 由项目死锁得到的教训
- 由GdkPixmap得到透明的GdkPixbuf
- 由日期得到一年中的第几周
- 由遍历序列得到二叉树
- 七、三大特性~继承
- QT —— 应用程序发布
- JavaScript Good Parts学习笔记-第三章 对象
- Dagger2
- 作为类空超曲面里生活的我们
- 由DocumentsUI 得到文件path
- 基础——仿射变换矩阵与warpAffine
- POJ 1472Instant Complexity(模拟+dfs)
- usaco fencing the cows
- JDK中java.io.InputStream源码
- 堆的标准模板
- poj2109
- Tortoisegit的setting中没有remote选项无法配置
- 关于java调用本地应用程序