Reputation: 234
I am writing a cordova android app to review footage from a dashcam via an OTG adapter. On some devices only, my app does not find external storage drives plugged through an OTG adapter.
All the other apps (file managers, etc) can find the drives and browse the files in them. However, I cannot reproduce the issue myself since it works flawlessly on all my android devices. The issue seems to be happening on less than 10% of android devices. I managed to debug via remote control with a friend that has the issue, and somehow his flash drive is never listed in file:///storage/ for my app, but all other file managers can see it. My app is granted permissions WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE (I was able to confirm that the permissions were correctly granted when the issue is present). I am wondering if I am doing it the right way, or if I am missing any additional permissions...
Here's some relevant content in config.xml
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="MediaPlaybackAllowsAirPlay" value="true" />
<preference name="AndroidExtraFilesystems" value="files,files-external,sdcard,cache,cache-external,root" />
<platform name="android">
<allow-intent href="market:*" />
<config-file parent="/manifest/application/activity" target="AndroidManifest.xml">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
</config-file>
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="cordova.plugins.diagnostic.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="cordova.plugins.diagnostic.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
</config-file>
<resource-file src="android_device_filter.xml" target="app/src/main/res/xml/device_filter.xml" />
</platform>
<plugin name="cordova-plugin-file" spec="^6.0.1" />
<plugin name="cordova.plugins.diagnostic" spec="^4.0.12">
<variable name="ANDROID_SUPPORT_VERSION" value="27.+" />
</plugin>
Here's the code I use to list all storage :
cordova.plugins.diagnostic.requestExternalStorageAuthorization(function(){
window.resolveLocalFileSystemURL('file:///storage/', function(storageDirEntry){
var rootDirReader = storageDirEntry.createReader();
rootDirReader.readEntries(function(drives){
for (var i in drives) if (drives[i].isDirectory) {
console.log('Searching In Drive: ', drives[i].name);
//...
}
}, console.error);
}, console.error);
}, console.error);
I am expecting to see the device listed directly as /storage/[DEVICE_ID]
like it does on most devices...
But on affected devices, there is no error in the console, and the only drive I see are /storage/emulated
and /storage/self
.
And within /storage/emulated/
there is only 0
which is certainly not the external flash drive.
Here's another piece of code that I have tried but it simply outputs an empty array with no error in the affected devices :
cordova.plugins.diagnostic.getExternalSdCardDetails(console.log, console.error);
I know that the drive is correctly plugged in and detected because other file managers on the same android device are detecting it and able to browse files. Also, these pieces of code run every few second for continuous detection... and it still never finds the drive.
Also interesting to note : Using the intent android.hardware.usb.action.USB_DEVICE_ATTACHED
, on affected devices, it actually opens up the app correctly when plugging in the flash drive, but then the app never finds it still.
Upvotes: 0
Views: 637