search

Home  >  Q&A  >  body text

java - android 调用录音机返回的Uri是file:///开头的?

这也是Uri?还是什么?使用contentResolver()查询不到目标信息啊?
不懂。。。。

还有想知道调用相机时不放extra参数,图片会在返回的intent中的一个名为data的extra中。
这个data的名字是哪里查来的?我在android官方api中没找到啊?求指教。。。。
伊谢尔伦伊谢尔伦2827 days ago739

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 14:49:25

    I encountered this problem a few days ago. I was trying to get the absolute path through Uri. The Uri returned by mobile phones from different manufacturers is different. Some of them start with file:///. You only need to replace the file header to get the absolute path. The above code

    /**
         * 通过Uri获取绝对路径
         * @param context
         * @param fileUri
         * @return
         */
        public static String getRealPath(Context context, Uri fileUri){
            String fileName = null;
            if(fileUri!= null){
                if (fileUri.getScheme().toString().compareTo("content")==0)
                {
                    fileName = getEachApiRealPath(context, fileUri); //自定义通过ContentResolver获取路径的方法
                }else if (fileUri.getScheme().compareTo("file") == 0)
                {
                    fileName = fileUri.toString().replace("file://", "");
                }
            }
            return fileName;
        }

    reply
    0
  • Cancelreply