SD Card available


#1

Hi guys i wanna make cool apps that can download file from url and save it to sd card if available
The problem is how to check if sd card is installed and how to save??
i do some research but cant find anything useful. thanks for advance…


#2

The file-system core module might be sufficient for what you need https://docs.nativescript.org/cookbook/file-system
If you really need to know about an SD card - on Android it’s something like the following:

const state = android.os.Environment.getExternalStorageState(); // this returns a string - https://developer.android.com/reference/android/os/Environment.html#getExternalStorageState()
if (state === android.os.Environment.MEDIA_MOUNTED) {
  /// should be good to go here
}

You’d want to wrap this in a platform check if you’re going to also target iOS with your NS app. The platform module has a isAndroid bool that is perfect to check if you’re running on android for this situation.