Save file to public directory using Cordova FileTransfer

I need to download files on my mobile device and make them accessible for other apps (using Android and iOS).

I managed to download a file to the SD card (cordova.file.externalDataDirectory), but this only exists on Android and even then I cannot rely on every device having an SD card.

  • Get the Google ID used in an in-app billing purchase
  • Create “ok glass” style menu, within glass app
  • Android - Change app Theme on onClick
  • GCM Error - googleCloudMessaging.register
  • ListView Creator called but no other methods
  • Using android support library 23.2 in build.gradle crashes app (XmlPullParserException: XmlPullParserException: invalid drawable tag vector)
  • When I download to the device storage (cordova.file.dataDirectory), the file is private to my app and therefore not accessible for other apps. The file can be opened in the InAppBrowser, but I would prefer to use the respective default app.

    Is there a way to get a path to a directory publicly available on all devices?

    The paths returned by the solution suggested in https://stackoverflow.com/a/21375812/3432305 are both private on Android…

    EDIT:

    I think I should describe my use case so it’s clearer what I’m trying to achieve: I want to open files from my in app chat using the respective default app (pdf viewer, image viewer etc.). Because the Cordova File Opener plugin only accepts files from the local file system, I need to save them first. But they don’t necessarily need to be accessible from outside my app afterwards…

    Related posts:

    Does ADT support Java 7 API
    How to prepare layout,drawable folders for 7“,10” android tablets for both lands...
    How to measure VRAM consumption on Android?
    “Unparseable date: 1302828677828” trying to deserialize with Gson a millisecond-...
    What is the maximum memory limits per application for Android 2.2?
    Video in WebView - ApplicationContext vs Activity Context
  • Remove Project from Android Studio
  • Android ImageView scale smaller image to width with flexible height without cropping or distortion
  • Google Maps API - Offset for Marker Image - Replace Marker - Not at GeoPosition
  • Navigation Drawer highlight selected item not working
  • How do you determine the audio latency (AudioTrack) on Android?
  • android: Determine security type of wifi networks in range (without connecting to them)
  • One Solution collect form web for “Save file to public directory using Cordova FileTransfer”

    On Android, external storage directories always exist; if the device doesn’t have a physical SD card, Android will emulate it. see getExternalStorageDirectory :

    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.

    Therefore cordova.file.externalDataDirectory will always resolve. However, for sharing data between apps, you probably want to use cordova.file.externalRootDirectory – External storage (SD card) root. See cordova-plugin-file.

    This way you can store files in a place that’s easier to access from another app e.g. /sdcard/my_shared_data/

    On iOS, it’s more difficult to share files because apps are intentionally isolated from each other due to security policy, as Apple’s Inter-App Communication Guide says:

    Apps communicate only indirectly with other apps on a device

    You best bet on iOS is to share the data by synching it via iCloud. See the section Configuring a Common Ubiquity Container for Multiple Apps in iCloud Design Guide, which says:

    … perhaps you provide two apps that interoperate and need
    access to each other’s files. In both of these examples, you obtain
    the needed access by specifying a common ubiquity container and then
    requesting access to it from each app.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.