简体   繁体   中英

Directory for saving/accessing files in Android

I'm currently developing an app in Android Studio for Android TV on a mac. Ultimately I want to load local image files as card images in a VerticalGridFragment where a card id and an image filename have matching numbers. For the sake of prototyping, right now I'm just trying to set up best practices (as a complete novice) with a single 1.jpg file that will appear on every card.

I'm using the included Android TV emulator and assume I shouldn't attempt to use access or make use of any OSX file system. So my two questions are:

  1. While I'm prototyping and trying to get 1.jpg to be the image for each card, where should I place this file in a manner that I can access using a file path string for internal storage, such as /root/1.jpg which I can later change to /root/$.jpg where $ is a dynamic id associated with each card. This needs to satisfy both the emulator being able to access the file, a device being able to access the file when the app is finished, and me being able to place files there from my host os while prototyping.

  2. A follow-on question. When the app is finished I obviously won't be relying on manually placing image files. Will the solution to the above also provide a straightforward means of saving images to this directory on a device?

Thanks.

Ok, I think I've got my head around this now:

Inside Android Studio, there's a Monitor utility in which there's a File Explorer. Using this, you can browse, and save to the directory structure that the emulator's using.

Most importantly, there is a standard assigned directory for apps to save and open from on internal storage. It can be found in the file browser at /data/data/com.applicationname/files/

From any app, it can be referenced for saving to or opening from using getFilesDir() , which answers question 2.

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