简体   繁体   中英

How can I read a file in Internal Storage without declaring the permission?

I'm writing an app that allows users to import their own data (via .zip's, .png's etc.) from an external location such as their downloads folder.

My app is correctly getting the file path from the URI, however I do not wish to require the WRITE_EXTERNAL_STORAGE permission in my app, which I need in order to read the file the user is providing me. I feel like Android should allow my app read permission to this file, since the user selected it.

Is there a way to have Android copy this file to a temporary location where I can read it, so that I do not need to ask the user for this permission?

If you don't want the permission, then there is a way for Android4.4 and above. Let the user import the data into the programdirectory, see also:

Starting in Android 4.4, the owner, group and modes of files on external storage devices are now synthesized based on directory structure. This enables apps to manage their package-specific directories on external storage without requiring they hold the broad WRITE_EXTERNAL_STORAGE permission. For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions. These synthesized permissions are accomplished by wrapping raw storage devices in a FUSE daemon.

Taken from this page -> https://source.android.com/devices/storage/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM