国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

由DocumentsUI 得到文件path

2019-11-09 14:59:54
字體:
來源:轉載
供稿:網友

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.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;    }

 

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滨州市| 仁化县| 嫩江县| 东山县| 石门县| 镇江市| 张家口市| 乳山市| 麦盖提县| 新乡市| 察隅县| 正镶白旗| 祁阳县| 普格县| 磐安县| 三门峡市| 河源市| 桑植县| 中牟县| 淮安市| 南投县| 修武县| 宁南县| 巢湖市| 图片| 竹北市| 上高县| 三亚市| 娱乐| 普兰县| 平泉县| 确山县| 盐津县| 镇康县| 沂源县| 方正县| 巫山县| 福泉市| 安平县| 唐山市| 安达市|