Get absolute path to assets folder in PhoneGap

后端 未结 3 844
旧时难觅i
旧时难觅i 2020-12-31 10:05

Is there a way to get the absolute path of an image in phonegap asset folder?

I need the absolute path to attach the image in a mail using EmailComposer plugin.

相关标签:
3条回答
  • 2020-12-31 10:20

    It looks like this is not possible.

    See https://groups.google.com/forum/#!topic/phonegap/Sw2wThOYm8c

    From Simon's response in that thread he states...

    "You can't do what you want to do. The files in the assets directory are not technically on the file system so they are not accessible via the File API. This means calling window. resolveLocalFileSystemURI() will not return you a FileEntry. It is properly returning an error code of 1 which is NOT_FOUND_ERR. "

    You need the absolute path of a file for the email attachments plugin to work. Unfortunately if the file resides in the assets folder, you cannot use cordova's file api to get the absolute path.

    There is a plugin that exists to copy files out of your assets folder and place them onto the sdcard. You can then pass the exact location of this file to the email attachments plugin. Unfortunately it looks like the plugin below is out of date if you are planning on using the newer cordova versions.

    https://github.com/gkcgautam/Asset2SD

    0 讨论(0)
  • 2020-12-31 10:29

    Pass 'file:///android_asset/www/img/logo.png' to window.resolveLocalFileSystemURI() and the resulting FileEntry.fullPath is what you want. Look at the documentation for detailed example: http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html

    0 讨论(0)
  • 2020-12-31 10:38

    Just in case somebody is still looking for a solution. Now Cordova implements a really easy way to get the current application directory (supported on Android, iOS and BlackBerry 10) :

    cordova.file.applicationDirectory

    For example, if you want to access an audio file in your res/audio directory (within your www), you just have to write that :

    cordova.file.applicationDirectory + 'res/audio/my-audio-file.mp3'

    Here is the complete documentation

    0 讨论(0)
提交回复
热议问题