Good. Part of my problem was that I got the slightly asynchronous nature of the file system API / cordova -plugin-file on the cord. I needed to refactor the code to get a list of files in order to display correctly, but as soon as I did, the files displayed correctly, regardless of where they are on the device.
Here is the applicable code. Please note that you will need the cordova-plugin file added to your Cordova / PhoneGap project and that it will not work in the browser. I actually have this block inside another if / then block - if it works in a browser, show html5 <input type=file> , if it is on a mobile device, show this block:
var localURLs = [ cordova.file.dataDirectory, cordova.file.documentsDirectory, cordova.file.externalApplicationStorageDirectory, cordova.file.externalCacheDirectory, cordova.file.externalRootDirectory, cordova.file.externalDataDirectory, cordova.file.sharedDirectory, cordova.file.syncedDataDirectory ]; var index = 0; var i; var statusStr = ""; var addFileEntry = function (entry) { var dirReader = entry.createReader(); dirReader.readEntries( function (entries) { var fileStr = ""; var i; for (i = 0; i < entries.length; i++) { if (entries[i].isDirectory === true) {
EDIT (February 2018) : even if you can see files in Android File Transfer, you may not receive any results programmatically, even if you have time to build permissions set in the Cordova application. This is because runtime checks have been added in Android (I believe> 6.0). There are a couple of plugins that can help get around this; at some point, I assume that the plugin file will also add automatic queries to it. Here is what I did with cli-7.0.1 :
In your config.xml set the necessary permissions for the application. You will need READ_EXTERNAL_STORAGE (and also write if you are going to do this). I also add two plugins that are referenced below:
<plugin name="cordova-plugin-device" source="npm" spec="1.1.6" /> <plugin name="cordova.plugins.diagnostic" spec="^3.7.1" /> <config-file platform="android" parent="/manifest" mode="replace"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </config-file>
Then, preferably somewhere in your application’s start code (i.e., the device’s ready event handler), check the execution permissions and add them if necessary:
if (device.platform === "Android") { // request read access to the external storage if we don't have it cordova.plugins.diagnostic.getExternalStorageAuthorizationStatus(function (status) { if (status === cordova.plugins.diagnostic.permissionStatus.GRANTED) { console.log("External storage use is authorized"); } else { cordova.plugins.diagnostic.requestExternalStorageAuthorization(function (result) { console.log("Authorization request for external storage use was " + (result === cordova.plugins.diagnostic.permissionStatus.GRANTED ? "granted" : "denied")); }, function (error) { console.error(error); }); } }, function (error) { console.error("The following error occurred: " + error); }); }