访问/ SD卡中的Andr​​oid 4.2 [英] Access /sdcard in Android 4.2

查看:125
本文介绍了访问/ SD卡中的Andr​​oid 4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,需要直接访问SD卡的根文件夹,但它似乎在安卓4.2,标准/ SD卡目录现在指向一个模拟SD卡特定于运行应用程序的用户。这是不好的,因为我的应用程序需要访问存储在SD卡的顶层文件。有谁知道如何直接访问SD卡中的Andr​​oid 4.2?

I am developing an app that needs direct access to the root folder of the sdcard, however it seems in Android 4.2, the standard /sdcard directory now points to an "emulated" sdcard specific to the user running the app. This is not good, as my app requires access to a file that is stored on the top level of the sdcard. Does anyone know how to directly access the sdcard in Android 4.2?

推荐答案

你能使用的存储目录作为文件类型? (的java.io.File

Can you use the storage directory as a File type? (java.io.File)

如果是这样,你可以得到外部存储(通常SD卡,但会在手机上没有SD卡主存储器)使用code像这样在你的方法:

If so, you can get the external storage (Typically SD card, but will be main storage on phones with no SD card) by using code such as this in your method:

File path = Environment.getExternalStorageDirectory();

此外,存储访问需要 READ_EXTERNAL_STORAG​​E 允许在你的Andr​​oid清单 - 以 WRITE_EXTERNAL_STORAG​​E 如果任何数据是被需要改性。下面是这些权限,因为它们将出现在该清单:

Additionally, access of storage requires READ_EXTERNAL_STORAGE permission in your Android Manifest - with WRITE_EXTERNAL_STORAGE being needed if any data is modified. Here are these permissions as they would appear in the manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

来源:

http://developer.android.com/reference/android/os/ Environment.html http://developer.android.com/reference/android/Manifest.permission.html

这篇关于访问/ SD卡中的Andr​​oid 4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆