ionic v4 not able to access external sd card

Viewed 520

please anyone help me to access device external memory(sd card) using Ionic-v4 and Angular 6 and platform is Android.

I have tried using Ionic native file, but it shows the path of Internal memory only.

// file system access
import { File } from '@ionic-native/file/ngx';
// file opener
import { FileOpener } from '@ionic-native/file-opener/ngx';
// document viewer
import { DocumentViewer, DocumentViewerOptions } from '@ionic-native/document-viewer/ngx';

............

let path = this.file.externalRootDirectory;
this.file.checkDir(path, 'mydir').then(_ => {
  console.log('Directory exists');
  this.showAlert('Directory exists','','Directory exists: '+path);
}).catch(err =>{
  console.log('Directory doesnt exists');
  this.showAlert('Directory doesnt exists','','Directory doesnt exists: '+path);
});

Then I tried getExternalSdCardDetails() method of cordova-diagnostic-plugin

import { Diagnostic } from '@ionic-native/diagnostic';

.........

this.diagnostic.getExternalSdCardDetails().then(obj => {
  this.showAlert('xxxxxxxx','','xxxxxxxx: '+JSON.stringify(obj));
}, (errData)=>{

});

But it is not working.

I am new to Ionic, please anyone help to just read the external memory or sd-card in Ionic4 and angular6 for android platform. Thank you.

2 Answers

I think you can use externalApplicationData in your app and move the app to an external SD card. Go to App Details > Storage. If the option to move to external is not available, enable developer options on the phone and "force enable apps to external card". Now, the app will have full access to its own sand-boxed data on external card, even though the Ionic file will still report something like "file://storage/emulated/0".

with file plugin you can use like that

await this.file.listDir(this.file.externalRootDirectory, '')

Or you can refer demo here in link that's a file manager app using ionic

https://github.com/JainBhavesh/FileManagerIonic4
Related