FileProvider - 使用默认InternalStorage文件夹,文件路径模糊 [英] FileProvider - use default InternalStorage folder, filePaths ambiguity

查看:710
本文介绍了FileProvider - 使用默认InternalStorage文件夹,文件路径模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

报告说,文档中的:


  

一个FileProvider只能产生在内容URI的文件
  您事先指定的目录。要指定一个目录,
  在XML中指定其存储区域和路径,使用的子元素
  的元素。例如,下面的路径元素告诉
  您打算请求内容的URI的图像FileProvider /
  你的私人文件区的子目录。

 <路径的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
 <文件路径名=my_images路径=图像//>
 ...< /路径>


如果我不想使用一个子目录,但默认internalstorage目录?

<醇开始=2>
  • 这是从文档的示例文件路径的XML文件:

    &LT;路径的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

     &LT;文件路径名=my_images路径=图像//&GT;&LT;文件路径名=my_docs路径=文档//&GT;


  • 当我在我的项目中使用它,我得到属性缺少的Andr​​oid命名空间preFIX

    我应该增加吗?难道文件有错误的,或者有什么地方我犯了一个错误?


    解决方案

      

    如果我不想使用一个子目录,但默认internalstorage目录?


    留出路径属性。


      

    当我在我的项目中使用它,我得到属性缺少的Andr​​oid命名空间preFIX


    我不知道是什么给你这个消息。如果是IDE,它可能是在IDE中的错误。从技术上讲,我们甚至不需要命名空间声明,虽然我的示例应用程序拥有它。


      

    我应该增加吗?


    没有。 这个示例应用程序没有它的正常工作。

    It says in the documentation:

    A FileProvider can only generate a content URI for files in directories that you specify beforehand. To specify a directory, specify the its storage area and path in XML, using child elements of the element. For example, the following paths element tells FileProvider that you intend to request content URIs for the images/ subdirectory of your private file area.

     <paths xmlns:android="http://schemas.android.com/apk/res/android">
     <files-path name="my_images" path="images/"/>
     ... </paths>
    

    What If I dont want to use a subdirectory, but the default internalstorage directory?

    1. This is an example file paths xml file from the documentation:

      < paths xmlns:android="http://schemas.android.com/apk/res/android" >

      <files-path name="my_images" path="images/"/>
      
      <files-path name="my_docs" path="docs/"/>
      

    When I use it in my project, I get "Attribute is missing the Android namespace prefix"

    Should I add it? Is it possible that the documentation has a mistake in it, or have I made a mistake somewhere?

    解决方案

    What If I dont want to use a subdirectory, but the default internalstorage directory?

    Leave off the path attribute.

    When I use it in my project, I get "Attribute is missing the Android namespace prefix"

    I have no idea what is giving you this message. If it is an IDE, it is probably a bug in the IDE. Technically, we don't even need the namespace declaration, though my sample app has it as well.

    Should I add it?

    No. This sample app works fine without it.

    这篇关于FileProvider - 使用默认InternalStorage文件夹,文件路径模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆