Titanium - Android external storage - create new directory and then write files into it

后端 未结 3 1538
忘了有多久
忘了有多久 2021-01-27 00:30

Can we not simply create new directory programmatically on external SD card (not internal memory of device) in Android and can we not write files on SD card?

Is Titanium

3条回答
  •  不思量自难忘°
    2021-01-27 01:02

    You can use System class to get storage variables like below

    To get the internal SD card you can use

    String extStore = System.getenv("EXTERNAL_STORAGE");
    File f_exts = new File(extStore);
    

    To get the external SD card you can use

    String secStore = System.getenv("SECONDARY_STORAGE");
    File f_secs = new File(secStore);
    

    You can choose where to create folder and which one to use.

    EDIT

    Environment.getExternalStorageDirectory() Details

    • Return the primary shared/external storage directory.
    • This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().

    Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

    Reference from Environment

    Hope it'll help.

提交回复
热议问题