https://developer.android.com/training/secure-file-sharing/setup-sharing.htmlAndroid 7 nougat,如何從uri的傳入意圖獲取文件路徑?
我知道在android nougat中改變文件策略。 文件共享到其他應用程序的通緝應用程序通過FileProvider生成uri。 uri格式爲content://com.example.myapp.fileprovider/myimages/default_image.jpg
。
我想知道如何從uri產生FileProvider.getUriForFile()
獲得filepath。 因爲我的應用程序需要知道物理文件路徑,以保存,加載,readinfo等 是有可能
[總之]
- 我的應用程序在其他應用中收到的意圖URI在andorid 7牛軋糖。
- uri格式爲
content://com.example.myapp.fileprovider/myimages/default_image.jpg
- 也許它是由
FileProvider.getUriForFile
生成的。 - 我想知道從uri獲取文件路徑的方式。
- 我只能從
getContentResolver().openFileDescriptor()
獲取MIME類型,顯示名稱,文件大小和讀取binay。 但我想知道文件路徑。
如果您可以從流中進行二進制讀取,您可以從流中讀取數據。用它。不需要文件路徑。只有文件提供者應該能夠告訴你文件路徑,但它不會。反思。重新設計。你不需要文件路徑。 – greenapps
「我的應用程序需要知道物理文件路徑才能保存,加載,讀取信息等。」 - 然後使用'ContentResolver'和'openInputStream()'製作你自己的內容副本。您不僅可以確定路徑,但即使可以,也很可能無法訪問該文件的文件系統。 – CommonsWare