简体   繁体   English

在Android中保存/访问文件的目录

[英]Directory for saving/accessing files in Android

I'm currently developing an app in Android Studio for Android TV on a mac. 我目前正在Android上为Android TV开发Android应用程序。 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. 最后,我想在VerticalGridFragment中将本地图像文件作为卡片图像加载,其中卡片ID和图像文件名具有匹配的数字。 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. 为了进行原型设计,我现在只是尝试使用单个1.jpg文件设置最佳实践(作为一个完整的新手),该文件将出现在每张卡片上。

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. 我正在使用附带的Android TV模拟器,并假设我不应该尝试使用访问或使用任何OSX文件系统。 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. 虽然我正在进行原型设计并试图让1.jpg成为每张卡的图像,但我应该在哪里放置这个文件,我可以使用文件路径字符串进行内部存储,例如/root/1.jpg我可以稍后更改为/root/$.jpg ,其中$是与每张卡相关联的动态ID。 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. 在Android Studio中,有一个Monitor实用程序,其中有一个文件资源管理器。 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/ 它可以在文件浏览器中/data/data/com.applicationname/files/

From any app, it can be referenced for saving to or opening from using getFilesDir() , which answers question 2. 从任何应用程序,可以引用它来保存或使用getFilesDir()来回答问题2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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