简体   繁体   English

如何正确使用android内部和外部存储?

[英]How properly work with android internal and external storage?

i am creating Download Manager app therefore my requirement is to store files on sdcard and phone internal storage if sdcard not available and access them later to open files from app. 我正在创建Download Manager应用程序,因此,如果没有sdcard,我的要求是将文件存储在sdcard和电话内部存储中,并在以后访问它们以从应用程序打开文件。 i have read almost every post to store files but it confuses me to decide which method is best to use because there are lot of different ways to do.i want to create folder inside external(if available) or internal then store files inside this folder. 我已经阅读了几乎所有文章来存储文件,但是这使我难以决定哪种方法是最好的选择,因为有很多不同的方法可以执行。 。
Now here can anyone tell me what is best way to access sdcard if available otherwise internal storage 现在有人可以告诉我什么是访问sdcard的最佳方法(如果有),否则可以使用内部存储

Storage options in android is the place where you need to go. android中的存储选项是您需要去的地方。 You will know how to Checking media availability from there, more specifically external storage . 您将知道如何从那里检查媒体可用性,尤其是外部存储

The sample code is 示例代码是

/* Checks if external storage is available for read and write */ / *检查外部存储是否可用于读取和写入* /

public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

/* Checks if external storage is available to at least read */ / *检查外部存储是否至少可读取* /

public boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) ||
        Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}

Use Environment to access ExternalStorageDirectory 使用环境访问ExternalStorageDirectory

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

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