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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

由DocumentsUI 得到文件path

2019-11-09 14:05:16
字體:
供稿:網(wǎng)友

uriForCapture = content://com.android.PRoviders.media.documents/document/video%3A98

uriForCapture = content://media/external/video/media/98

針對這2中uri第二種通過查多媒體數(shù)據(jù)庫很容易得到文件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;    }

 

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌苏市| 白河县| 漠河县| 扎鲁特旗| 外汇| 泸定县| 玉环县| 读书| 温州市| 鄱阳县| 平果县| 方正县| 六枝特区| 威远县| 余姚市| 西青区| 铁岭县| 交口县| 封开县| 安阳县| 高州市| 桂东县| 石棉县| 铜山县| 井陉县| 喜德县| 洛浦县| 昌宁县| 宝清县| 辉县市| 吐鲁番市| 浏阳市| 利津县| 嘉善县| 广元市| 达尔| 深圳市| 海林市| 宝坻区| 镇巴县| 施甸县|