Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full pah of Download directory #2

Closed
jfoclpf opened this issue Jan 10, 2021 · 7 comments
Closed

Full pah of Download directory #2

jfoclpf opened this issue Jan 10, 2021 · 7 comments

Comments

@jfoclpf
Copy link

jfoclpf commented Jan 10, 2021

Is your feature request related to a problem? Please describe.
I want to have the full path of Downloads directory

Describe the solution you'd like
a full path of a directory

Describe alternatives you've considered
I tried this as described in the docs:

if (navigator.Env) {
    console.log("Env object in navigator");
    navigator.Env.getDirectory("Downloads", 
        function (path) {
            if (path) {
                console.log("getDirectory(Documents) returns: " + path);
            }
        },
        function (error) {
            console.log("getDirectory error: " + error);
        }
    );
} else {
    console.log("Plugin error: Env plugin not found (is it installed?)");
}

The problem is that path returns only Download and not the full path.
I'm doing cordova.file.externalRootDirectory + path but not sure if this is correct

Additional context

cordova info Output from my cordova info
$ cordova info
6.0.0
6.0.0

Cordova Packages:

    cli: 10.0.0
        common: 4.0.2
        create: 3.0.0
        lib: 10.0.0
            common: 4.0.2
            fetch: 3.0.0
            serve: 4.0.0

Project Installed Platforms:

    android: 9.0.0
    browser: null

Project Installed Plugins:

    cordova-pdf-generator: 2.1.1
    cordova-plugin-app-version: 0.1.12
    cordova-plugin-camera: 5.0.1
    cordova-plugin-compat: 1.2.0
    cordova-plugin-device: 2.0.3
    cordova-plugin-email-composer: 0.8.15
    cordova-plugin-env: 1.0
    cordova-plugin-file: 6.0.1
    cordova-plugin-geolocation: 2.4.3
    cordova-plugin-inappbrowser: 4.0.0
    cordova-plugin-is-debug: 1.0.0
    cordova-plugin-mobile-ocr: 3.1.2
    cordova-plugin-network-information: 2.0.2
    cordova-plugin-screen-orientation: 3.0.2
    cordova-plugin-simple-image-resizer: 0.1.1
    cordova-plugin-splashscreen: 6.0.0
    cordova-plugin-statusbar: 2.4.3
    cordova-plugin-whitelist: 1.3.4
    es6-promise-plugin: 4.2.2

Environment:

    OS: Ubuntu 18.04.5 LTS (linux 5.4.0-60-generic) x64
    Node: v14.15.4
    npm: 6.14.11

android Environment:

    android:
*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Running /home/joao/Android/Sdk/tools/bin/avdmanager list target

Available Android targets:==============] 100% Fetch remote repository...       
----------
id: 1 or "android-24"
     Name: Android API 24
     Type: Platform
     API level: 24
     Revision: 2
----------
id: 2 or "android-25"
     Name: Android API 25
     Type: Platform
     API level: 25
     Revision: 3
----------
id: 3 or "android-26"
     Name: Android API 26
     Type: Platform
     API level: 26
     Revision: 2
----------
id: 4 or "android-27"
     Name: Android API 27
     Type: Platform
     API level: 27
     Revision: 3
----------
id: 5 or "android-28"
     Name: Android API 28
     Type: Platform
     API level: 28
     Revision: 6
----------
id: 6 or "android-29"
     Name: Android API 29
     Type: Platform
     API level: 29
     Revision: 4
----------
id: 7 or "android-R"
     Name: Android API 29, R preview (Preview)
     Type: Platform
     API level: R
     Revision: 4
----------
id: 8 or "android-30"
     Name: Android API 30
     Type: Platform
     API level: 30
     Revision: 3


Project Setting Files:

    config.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.form.parking.violation" version="2.6.4" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>Denúncia Estacionamento</name>
  <description>
        Envio de queixa de estacionamento ilegal a autoridade competente
    </description>
  <author email="joao.pimentel.ferreira@gmail.com" href="https://www.joaopimentel.com/">
        João Pimentel Ferreira
    </author>
  <content src="index.html"/>
  <icon height="512" src="res/icon/universal/icon4_512x512_playstore.png" width="512"/>
  <icon density="xhdpi" height="196" src="res/icon/universal/icon4_XHDPI_196x196_320dpi.png" width="196"/>
  <icon density="xxxhdpi" height="192" src="res/icon/universal/icon4_XXXHDPI_192x192_640dpi.png" width="192"/>
  <icon density="xxhdpi" height="144" src="res/icon/universal/icon4_XXHDPI_144x144_480dpi.png" width="144"/>
  <icon density="hdpi" height="72" src="res/icon/universal/icon4_HDPI_72x72_240dpi.png" width="72"/>
  <icon density="mdpi" height="48" src="res/icon/universal/icon4_MDPI_48x48_160dpi.png" width="48"/>
  <access origin="*"/>
  <allow-navigation href="*"/>
  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <preference name="windows-target-version" value="10.0"/>
  <preference name="windows-phone-target-version" value="10.0"/>
  <preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle"/>
  <preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets"/>
  <preference name="StatusBarOverlaysWebView" value="false"/>
  <preference name="StatusBarBackgroundColor" value="#FFFFFF"/>
  <preference name="StatusBarStyle" value="blacktranslucent"/>
  <hook src="hooks/importNpmPackages.js" type="before_prepare"/>
  <hook src="hooks/copyCredentials.js" type="before_prepare"/>
  <hook src="hooks/convertHbsToHtml.js" type="after_prepare"/>
  <hook src="hooks/minifyFiles.js" type="after_prepare"/>
  <platform name="android">
    <preference name="android-minSdkVersion" value="22"/>
    <preference name="android-targetSdkVersion" value="29"/>
    <allow-intent href="market:*"/>
    <icon height="512" src="res/icon/android/512.png" width="512"/>
    <icon density="xhdpi" height="192" src="res/icon/android/192.png" width="192"/>
    <icon density="xxxhdpi" height="192" src="res/icon/android/192.png" width="192"/>
    <icon density="xxhdpi" height="144" src="res/icon/android/144.png" width="144"/>
    <icon density="hdpi" height="72" src="res/icon/android/72.png" width="72"/>
    <icon density="mdpi" height="48" src="res/icon/android/48.png" width="48"/>
    <splash density="hdpi" src="res/screen/android/screen-hdpi-portrait.png"/>
    <splash density="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png"/>
    <splash density="ldpi" src="res/screen/android/screen-ldpi-portrait.png"/>
    <splash density="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png"/>
    <splash density="mdpi" src="res/screen/android/screen-mdpi-portrait.png"/>
    <splash density="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png"/>
    <splash density="xhdpi" src="res/screen/android/screen-xhdpi-portrait.png"/>
    <splash density="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png"/>
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
  </platform>
</widget>

    package.json:
--- Start of Cordova JSON Snippet ---
{
  "plugins": {
    "cordova-plugin-geolocation": {},
    "cordova-plugin-email-composer": {},
    "cordova-plugin-file": {},
    "cordova-plugin-statusbar": {},
    "cordova-plugin-screen-orientation": {},
    "cordova-plugin-device": {},
    "cordova-plugin-whitelist": {},
    "cordova-plugin-network-information": {},
    "cordova-plugin-compat": {},
    "cordova-pdf-generator": {},
    "cordova-plugin-splashscreen": {},
    "cordova-plugin-inappbrowser": {},
    "cordova-plugin-is-debug": {},
    "cordova-plugin-app-version": {},
    "cordova-plugin-camera": {
      "ANDROID_SUPPORT_V4_VERSION": "27.+"
    },
    "cordova-plugin-mobile-ocr": {},
    "cordova-plugin-simple-image-resizer": {
      "ANDROID_EXIFINTERFACES_VERSION": "27.+"
    },
    "cordova-plugin-env": {}
  },
  "platforms": [
    "browser",
    "android"
  ]
}
--- End of Cordova JSON Snippet ---

@eb1
Copy link
Contributor

eb1 commented Jan 11, 2021

Hi João -

It looks like this might require a new method (and some thought on my part). Android has deprecated the Environment.GetExternalPublicStorageDirectory() that returned the entire path, to tighten security (see https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory()).

@jfoclpf
Copy link
Author

jfoclpf commented Jan 11, 2021 via email

@eb1
Copy link
Contributor

eb1 commented Jan 11, 2021

Hi João - for now, I've updated the plugin with access to the getExternalStorageDirectory() call (this is in v.1.1.0 of the plugin, but it might take some time for npm to refresh properly. You can always pull down the plugin directly if needed).

Longer term, I'm not sure what the solution is. You could concatenate to build the path like you've been doing above, or use some sort of fallback tree like we're doing in Adapt It Mobile (see ~line 3250 of DocumentViews.js here: https://github.com/adapt-it/adapt-it-mobile/blob/master/www/js/views/DocumentViews.js -- I'm just going until I find a usable directory, and then creating a subdirectory under that to store our exported files). I'm not seeing in the Android docs how (or if) we're supposed to be using shared folders like Downloads. Everything seems to be referring to documents created by a specific app and only to be used for that app.

I think, though, that File Explorer should be able to find app-specific files under cordova.file.externalRootDirectory. I can't recall having a problem finding files once they were exported.

@eb1
Copy link
Contributor

eb1 commented Jan 11, 2021

Looks like npm refreshed with the 1.1.0 release of cordova-plugin-env.

I'm marking this issue closed for the short term, because the getExternalStoragePublicDirectory() method does return a full path to the specified directory; albeit with an API that has an expiration date. :-/

@eb1 eb1 closed this as completed Jan 11, 2021
@eb1
Copy link
Contributor

eb1 commented Jan 11, 2021

I should add -- if you do come across a future-proof way of getting at the full path for these directories, I'd be glad to fold in a pull request. Thanks for reporting the issue!

@jfoclpf
Copy link
Author

jfoclpf commented Jan 11, 2021

Thanks Erik. Do kindly check also this thread from cordova-plugin-file, if you haven't seen yet:
apache/cordova-plugin-file#426 (comment)

Since Android does not allow access to shared folders in API 30, I think in cordova they might probably need some sort of file picker, as they recommend in the docs of android.

@eb1
Copy link
Contributor

eb1 commented Jan 11, 2021

Wow. It'll be interesting to see how they implement the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants