简体   繁体   English

知道SD卡Path Android的最佳方法

[英]Best way to know sd card Path Android

I need to know in the most of the devices the sd card path. 我需要了解大多数设备中的SD卡路径。 I have some problems for that I actually use: 我实际使用的一些问题:

 Environment.getExternalStorageDirectory();

But some phones don't return correct path... I don't know why. 但是有些电话无法返回正确的路径...我不知道为什么。

Which is the best way to check Sd Card Path for different devices and OS versions? 检查不同设备和操作系统版本的SD卡路径的最佳方法是哪种?

There is no "sd card path" in Android. Android中没有“ SD卡路径”。

At the present time, Android has internal storage and external storage, and that is it. 目前,Android具有内部存储和外部存储,就是这样。 Environment.getExternalStorageDirectory(); returns the root of external storage. 返回外部存储的根。 Whether external storage is: 外部存储是否为:

  • on the same partition of the on-board flash as is used for internal storage, or 在与内部存储相同的板载闪存分区上,或者
  • on a separate partition of the on-board flash, or 在板载闪存的单独分区上,或
  • is some removable drive, like a microSD card, or 是一些可移动驱动器,例如microSD卡,或者
  • is something else entirely 完全是另外一回事

is up to the device manufacturer. 由设备制造商决定。

Similarly, if the device manufacturer offers additional data stores (eg, a removable card in addition to external storage as part of on-board flash), right now, those additional data stores are for the exclusive use of the device manufacturer. 类似地,如果设备制造商提供其他数据存储(例如,除了外部存储作为板载闪存的一部分之外,还提供了可移动卡),那么这些额外的数据存储仅供设备制造商专用。 That manufacturer may elect to document how you can use them, or the manufacturer may integrate those data stores with something else that you can access (eg, have multimedia files by indexed and accessible via MediaStore ). 该制造商可以选择记录如何使用它们,或者制造商可以将这些数据存储与您可以访问的其他内容集成在一起(例如,通过索引建立多媒体文件并可以通过MediaStore访问)。

You can read more about this in the documentation on external storage . 您可以在外部存储的文档中阅读有关此内容的更多信息。

So, by definition, Environment.getExternalStorageDirectory(); 因此,根据定义, Environment.getExternalStorageDirectory(); is "the correct path" representing external storage. 代表外部存储设备的“正确路径”。

I think this is best one ... 我认为这是最好的...

 Cursor cursor = getContentResolver().query(_uri, new String[] { ndroid.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                      cursor.moveToFirst();

This is always the best approach: 这始终是最好的方法:

Environment.getExternalStorageDirectory();

You could also get the environmental variable which is on all Android devices like this: 您还可以获取所有Android设备上的环境变量,如下所示:

String sdcardPath = System.getenv("EXTERNAL_STORAGE");

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

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