国产探花免费观看_亚洲丰满少妇自慰呻吟_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;    }

 

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 谢通门县| 新龙县| 安岳县| 收藏| 西乌珠穆沁旗| 溆浦县| 广灵县| 满洲里市| 天津市| 平顺县| 民丰县| 塔城市| 从化市| 四子王旗| 临洮县| 农安县| 衡南县| 杂多县| 建平县| 乌拉特前旗| 弥渡县| 山阴县| 二连浩特市| 钟山县| 洛扎县| 临洮县| 阳山县| 宁德市| 平潭县| 辛集市| 绥阳县| 长丰县| 道真| 衡阳市| 永平县| 海晏县| 历史| 工布江达县| 鄂温| 深圳市| 集贤县|