简体   繁体   English

如何处理内置存储和外部SD卡?

[英]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.

相关问题 如何获得外部存储SD卡大小(带有安装的SD卡)? - How to get an External storage sd card size (With Mounted SD card)? 设备声称外部存储,但我没有SD卡 - Device claims external storage, yet I have no SD card 如何使用android studio从应用程序中的内部或外部存储(SD卡)读取文件? - How can I read Files from Inter or External Storage (SD Card) in app using android studio? 如何在外部SD卡中写入文件而不在设备存储中? - How to write a file in external sd card and not in device storage? 如何在Xamarin.android中的mashmallow中写入外部存储SD卡 - How to write on external storage sd card in mashmallow in xamarin.android 如何在 android 中访问外部存储(可移动 SD 卡)? - How to get access to External Storage (The removable SD Card) in android? 如何从可移动SD卡(第二外部存储)中删除文件? - How to delete file from removable sd card (second external storage)? Android:如何获取外部SD卡的存储空间? - Android: How to get storage of external sd-card? Nativescript:如何将文件保存在外部存储(SD 卡)中 - Nativescript: How to save a file in external storage (SD card) 如何查找内部电话存储,个人数据,内部SD卡,外部SD卡和内存大小的路径? - How to find Path of Internal Phone Storage, Personal Data, Internal SD Card, External SD Card and Memory Size?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM