解决调用系统自带摄像头录像时从uri里面拿到的路径为空

在魅族3 Android 5.0设备上,调用系统摄像头录像后,从uri获取路径时发现为空。通过研究发现,Android 4.4之前的uri与之后的格式不同。解决方案是采用特定的代码处理uri,从而成功获取录像路径。
摘要由CSDN通过智能技术生成

首先感谢http://www.2cto.com/kf/201502/376975.html这篇文章的创作者
前几天调用系统摄像头录像后保存到一个路径上传视频 (魅族3 android 5.0),发现拿到的uri拿不到路径为空,找了好久找不到解决方法,结果发现android4.4之前和之后的uri格式是不同的,输出uri发现他的格式是这样的

content://com.android.providers.media.documents/document/image%2706

而以前用的uri是这样的

Uricontent://media/extenral/images/media/17766

4.4之前 所以我们使用以前的这种方法是用不了的

if (data.getScheme().toString().compareTo("content") == 0) {
                                    cursor = getContentResolver().query(data,
                                            new String[] {Audio.Media.DATA}, null, null, null);
                                    if (cursor.moveToFirst()) {
                                        filename = cursor.getString(0);
                                    }
                                }else if (data.getScheme().toString().compareTo("file") == 0)         //file:///开头的uri
                                {
                                    filename = data.toString();
                                    filename = data.toString().replace("file://", "");
                                    //替换file://
                                    if(!filename.startsWith("/mnt")){
                                        //加上
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值