[英]How do I handle built-in storage AND an external SD card?
Okay, so I've done as much research as I can to try and figure out if I'm doing anything wrong, but nothing on Google or the Android tutorials could really answer me in my scenario. 好的,所以我已经尽了最大的努力来找出我做错了什么,但是Google或Android教程中的任何内容都无法真正回答我的情况。
The Scenario: 场景:
Let's say I have an Android device that comes with 16GB of built-in storage. 假设我有一个配备16GB内置存储空间的Android设备。 Let's also assume that the device has a 32GB SD scard. 我们还假设设备的SD卡容量为32GB。 Basically, the device has a total 48GB of storage space. 基本上,该设备总共有48GB的存储空间。 My app needs to scan every user-accessible location on the device. 我的应用程序需要扫描设备上每个用户可访问的位置。 In other words, I need to be able to access and read every place that a regular user (non-root) can read and write to. 换句话说,我需要能够访问和读取普通用户(非root用户)可以读写的每个位置。
What I'm doing right now: 我现在正在做什么:
I'm using the recommended Environment.getExternalStorageDirectory()
which points me to /mnt/sdcard
. 我正在使用推荐的Environment.getExternalStorageDirectory()
,它将我指向/mnt/sdcard
。
The Question: 问题:
Is Environment.getExternalStorageDirectory()
going to give me access to every user-accessible storage on the device? Environment.getExternalStorageDirectory()
是否会让我访问设备上每个用户可访问的存储? I'm confused because there can be 16GB of built-in storage and 32GB of SD card storage, but how does Android handle the two separate locations? 我很困惑,因为可以有16GB的内置存储空间和32GB的SD卡存储空间,但是Android如何处理两个单独的位置? Does it simply combine the two into a singular /mnt/sdcard
or am I only able to access one of the two storage directories with my line of code? 它是将两者简单地组合成一个单独的/mnt/sdcard
还是我只能用我的代码行访问两个存储目录之一?
Sorry if this sounds like a noob question, but coming from an iPhone background where the only storage available is internal storage, I'm really stumped by Android's method of handling this situation. 抱歉,如果这听起来像个菜鸟问题,但是来自iPhone的背景,其中唯一可用的存储空间是内部存储空间,我真的为Android处理这种情况的方法而感到困惑。 Thanks for all your help! 感谢你的帮助!
Is Environment.getExternalStorageDirectory() going to give me access to every user-accessible storage on the device? Environment.getExternalStorageDirectory()是否会让我访问设备上每个用户可访问的存储?
No. It points you to external storage . 否。它将您指向外部存储 。
how does Android handle the two separate locations? Android如何处理两个不同的位置?
Android itself mostly only cares about the one spot designated as external storage. Android本身仅关心一个指定为外部存储的位置。 Anything above and beyond that is device-specific and is up to the manufacturer (or, possibly, ROM mod maintainer). 除此以外的任何事情都是特定于设备的,并取决于制造商(或可能是ROM mod维护者)。
This is why you do not see anything in the current Android SDK for accessing multiple volumes that all might be considered "external storage". 这就是为什么您在当前的Android SDK中看不到任何东西来访问多个可能被视为“外部存储”的卷的原因。
Does it simply combine the two into a singular /mnt/sdcard 它是否只是将两者合并成一个单一的/ mnt / sdcard
No. 没有。
or am I only able to access one of the two storage directories with my line of code? 或者我只能用我的代码行访问两个存储目录之一?
Yes. 是。
UPDATE : I wrote a series of blog posts to try to help developers make sense of the Android storage situation. 更新 :我写了一系列博客文章 ,试图帮助开发人员了解Android的存储情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.