首先感谢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是这样的
Uri : content://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")){
//加上