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

 

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洪湖市| 凌云县| 东港市| 诏安县| 石门县| 旺苍县| 潞西市| 界首市| 吴川市| 怀集县| 常山县| 苍梧县| 乌审旗| 嘉兴市| 都兰县| 福鼎市| 清水县| 泰来县| 廊坊市| 瑞丽市| 宽城| 葵青区| 尼木县| 福清市| 确山县| 子长县| 栾川县| 龙州县| 凉山| 扶余县| 利川市| 宁都县| 呼伦贝尔市| 义乌市| 府谷县| 岑巩县| 苗栗县| 无棣县| 普洱| 武穴市| 十堰市|