<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                > 編寫:[jdneo](https://github.com/jdneo) - 原文:[http://developer.android.com/training/secure-file-sharing/setup-sharing.html](http://developer.android.com/training/secure-file-sharing/setup-sharing.html) 為了將文件安全地從你的應用程序發送給其它應用程序,你需要對你的應用進行配置來提供安全的文件句柄(Content URI的形式)。Android的[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)組件會基于你在XML文件中的具體配置,為文件創建Content URI。這節課會向你展示如何在你的應用程序中添加[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)的默認實現,以及如何指定你要共享的文件。 > **Note:**[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)類隸屬于[v4 Support Library](http://developer.android.com/tools/support-library/features.html#v4)庫。關于如何在你的應用程序中包含該庫,可以閱讀:[Support Library Setup](http://developer.android.com/tools/support-library/setup.html)。 ### 指定FileProvider 為你的應用程序定義一個[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)需要在你的Manifest清單文件中定義一個字段,這個字段指明了需要使用的創建Content URI的Authority。除此之外,還需要一個XML文件的文件名,這個XML文件指定了你的應用可以共享的目錄路徑。 下面的例子展示了如何在清單文件中添加[`<provider>`](http://developer.android.com/guide/topics/manifest/provider-element.html)標簽,來指定[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)類,Authority和XML文件名: ~~~ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application ...> <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.example.myapp.fileprovider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" /> </provider> ... </application> </manifest> ~~~ 這里,[android:authorities](http://developer.android.com/guide/topics/manifest/provider-element.html#auth)屬性字段指定了你希望使用的Authority,該Authority針對于[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)所生成的content URI。在這個例子中,這個Authority是“com.example.myapp.fileprovider”。對于你自己的應用,要用你的應用程序包名([android:package](http://developer.android.com/guide/topics/manifest/manifest-element.html#package)的值)之后繼續追加“fileprovider”來指定Authority。要學習更多關于Authority的知識,可以閱讀:[Content URIs](http://developer.android.com/guide/topics/providers/content-provider-basics.html#ContentURIs),以及[android:authorities](http://developer.android.com/guide/topics/manifest/provider-element.html#auth)。 [`<provider>`](http://developer.android.com/guide/topics/manifest/provider-element.html)下的子標簽[`<meta-data>`](http://developer.android.com/guide/topics/manifest/meta-data-element.html)指向了一個XML文件,該文件指定了你希望共享的目錄路徑。“android:resource”屬性字段是這個文件的路徑和名字(無“.xml”后綴)。該文件的內容將在下一節討論。 ### 指定可共享目錄路徑 一旦你在你的Manifest清單文件中為你的應用添加了[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html),你需要指定你希望共享文件的目錄路徑。為了指定這個路徑,我們首先在“res/xml/”下創建文件“filepaths.xml”。在這個文件中,為每一個想要共享目錄添加一個XML標簽。下面的是一個“res/xml/filepaths.xml”的內容樣例。這個例子也說明了如何在你的內部存儲區域共享一個“files/”目錄的子目錄: ~~~ <paths> <files-path path="images/" name="myimages" /> </paths> ~~~ 在這個例子中,`<files-path>`標簽共享的是在你的應用的內部存儲中“files/”目錄下的目錄。“path”屬性字段指出了該子目錄為“files/”目錄下的子目錄“images/”。“name”屬性字段告知[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)向在“files/images/”子目錄中的文件的Content URI添加路徑分段(path segment)標記:“myimages”。 `<paths>`標簽可以有多個子標簽,每一個子標簽用來指定不同的共享目錄。除了`<files-path>`標簽,你還可以使用`<external-path>`來共享位于外部存儲的目錄;另外,`<cache-path>`標簽用來共享在你的內部緩存目錄下的子目錄。學習更多關于指定共享目錄的子標簽的知識,可以閱讀:[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)。 > **Note:** XML文件是你定義共享目錄的唯一方式,你不可以用代碼的形式添加目錄。 現在你有一個完整的[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)聲明,它在你應用程序的內部存儲中“files/”目錄下,或者是在“files/”中的子目錄下,創建文件的Content URI。當你的應用為一個文件創建了Content URI,該Content URI將會包含下列信息: - [`<provider>`](http://developer.android.com/guide/topics/manifest/provider-element.html)標簽中指定的Authority(“com.example.myapp.fileprovider”); - 路徑“myimages/”; - 文件的名字。 例如,如果你根據這節課的例子定義了一個[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html),然后你需要一個文件“default_image.jpg”的Content URI,[FileProvider](http://developer.android.com/reference/android/support/v4/content/FileProvider.html)會返回如下URI: ~~~ content://com.example.myapp.fileprovider/myimages/default_image.jpg ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看