0

I'm currently trying on a cordova test project that contains the download of a file to play on the music player afterwards. Basically the application should download a .mp3 file from my server and save it in the application storage or a user defined path (folder-select). As of now, i'm successfully downloading the file, i am able to select the custom path and to play the music files in the File Explorer app but somehow they are not showing up in the Music Player application or elsewhere. Also, even if i have defined external access in the config files, i can no write files to the sdcard. My current code to access the Filesystem looks like the following:

app.log('Filesystem', 'Requesting filesystem...');
  if (device.platform.toLowerCase() == "android") {
   app.log('Filesystem', 'Detected android device...');
   if(window.saveInMusic && window.musicPath){
    app.log('Filesystem', 'Selected storage persistent SD');
    window.resolveLocalFileSystemURL(window.musicPath, app.gotFS, app.fsFail);
   } else {
    app.log('Filesystem', 'Selected storage persistent Internal');
    window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, app.gotFS, app.fsFail);
   }
  } else {
   app.log('Filesystem', 'No device detected...');
   app.log('Filesystem', 'Selected storage DEFAULT (sandbox)');
   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.gotFS, app.fsFail);
  }

Somehow, all the cordova.file.external* directorys are null (like mentioned in the plugins md file) and the externalRootDirectory is returning "storage/emulated/0/appdir" (should return sdcard path). I have checked the permissions in config.xml and AndroidManifest.xml which look like the following:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.someorg.appname" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>AppName</name>
    <description>
        A basic Framework7 template for PhoneGap.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <preference name="android-minSdkVersion" value="14" />
  <preference name="AndroidPersistentFileLocation" value="Compatibility" />
  <preference name="AndroidExtraFilesystems" value="sdcard,cache" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <preference name="BackupWebStorage" value="none" />
    </platform>
    <preference name="DisallowOverscroll" value="true" />
    <plugin name="cordova-plugin-whitelist" spec="~1.2.0" />
    <plugin name="cordova-plugin-console" spec="~1.0.1" />
    <plugin name="cordova-plugin-statusbar" spec="~1.0.1" />
 <plugin name="cordova-plugin-compat" spec="~1.1.0" />
 <plugin name="cordova-plugin-device" spec="~1.1.5" />
 <plugin name="cordova-plugin-file" spec="~4.3.2" />
 <plugin name="cordova-plugin-file-transfer" spec="~1.6.2" />
 <plugin spec="https://github.com/ourcodeworld/cordova-ourcodeworld-filebrowser.git#96a57ef" source="git" />
</widget>

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.someorg.appname" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:label="Our Code World filepicker" android:name="com.ourcodeworld.plugins.filebrowser.DialogShowPicker">
            <intent-filter>
                <action android:name="com.ourcodeworld.plugins.filebrowser.DialogShowPicker" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:label="Filepicker" android:name="com.nononsenseapps.filepicker.FilePickerActivity" android:theme="@style/FilePickerTheme">
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="25" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
The application is in fact asking for these permissions on installation. I have also implemented a workaround (folderpicker) to choose the sdcard path manually. Sadly when i try my getDirectory function on that it is failing.

gotFS: function(fileSystem){
  window.fileSystem = fileSystem;
  app.log('Filesystem', 'Filesystem got!');
  var entry = "";
  if (device.platform.toLowerCase() == "android") {
   entry = fileSystem;
  } else {
   entry = fileSystem.root;
  }
  app.log('Filesystem', 'Setting up directory...');
  entry.getDirectory(window.appRootDirName, {
   create: true,
   exclusive: false
  }, app.dirReady, app.fsFail);
 },

I have already searched trought many stackoverflow pages and docs but i did not come up with any solution. I have installed the latest cordova 6.5 and also updated all plugins to the latest stable release. I'm happy for any advise.

Update: To be more clear, the user of the application should be able to use the downloaded media files as he is used to and not to manage and open them throught the app.

SkyRaptor
  • 58
  • 1
  • 5

1 Answers1

0

Take a look at here. The plugin cordova-plugin-file-opener2 solved this problem!

  • i'm not sure how this is solving the issue. The problem is that the downloaded file is not recognized by other applications, like the music player, like a sandbox. I have read of that i have to use resolveLocalFileSystemURL instead of resolveFileSystem to get a permanent location instead of an emulated one but this did also not work. – SkyRaptor Apr 11 '17 at 20:44
  • @user285814 the `opener2` converts the emulated location to a permanent, in my case the system opened `PDF's` and `MP3` correctly. All that you do is pass the `MIME TYPE` that you want. – Leandro Franciscato Apr 11 '17 at 20:53
  • I have implemented the plugin into my application and evaluated it. This plugin does just open the file. This is not the issue of my question. The issue is that OTHER applications wont access the Files. For example, the downloaded mp3 files wont show in the Music Player app (stock android). I have also rebooted the device to verify that the media libary is updated. Sadly the files wont show up as stated above. – SkyRaptor Apr 13 '17 at 19:33
  • Ok! Sorry about my interpretation error. So, the directory that you save the File is private? Here (http://cordova.apache.org/docs/en/6.x/reference/cordova-plugin-file/index.html#android-file-system-layout) we have which directory is private or no. – Leandro Franciscato Apr 17 '17 at 11:29