Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How to access SD card root directory with Ionic 2

$
0
0

@SansanIonic wrote:

Hello.

I'm developing a simple App with Ionic 2 which, among other things, has the functionality of a file browser set in the external storage of the device. The problem is that when I call the native method File.externalRootDirectory, instead of the root directory of the Sd card, I'm getting the root directory of the internal phone storage. This is the code:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { File } from '@ionic-native/file';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

    private dirs: string[];
    nativepath: string;

    constructor(public navCtrl: NavController, private fileCtrl: File) {
         this.goToDir("");
    }

    public goToDir(dir: string)
    {
        this.fileCtrl.listDir(this.fileCtrl.externalRootDirectory, dir).then(
            (list) => {
                this.loadList(list);
            }
        );
    }

    public loadList(list: any)
    {
        for (let i=0; i<list.length; i++)
        {
            this.dirs[i] = list[i].fullPath;
        }
    }

I've been testing this with Android 4.4 and 6.0. I have both ionic and cordova updated to the latest.

As I said, this code doesn't return the root of external storage, it returns the root of internal storage (dirs: /Android, /DCIM, /Download, etc). I'm new to Ionic (and web development with angular) and I don't see what I'm doing wrong. So I'd be glad if someone can help.

Thanks beforehand.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>