Cordova File Transfer Plugin didn't work in Android and Ionic2

I followed the ionic2 file transfer example as described here: GitHub - dsgriffin/ionic-3-file-transfer-example: 📁 File Transfer in Ionic 3 using Ionic Native's File and Transfer modules

Here is my code:

import {Component} from ‘@angular/core’;
import {Transfer, Cordova} from ‘ionic-native’;

@Component({
templateUrl: ‘build/pages/hello-ionic/hello-ionic.html’
})
export class HelloIonicPage {
constructor() {

}

download() {
let pathToSaveTo = cordova.file.dataDirectory + ‘abc.docx’;

alert(pathToSaveTo);

let ft = new Transfer();

ft.download(encodeURI('https://mydomain.com/abc.docx'), pathToSaveTo, true)
        .then((data) => {
            alert("Success");
        }, (err) => {
            alert(err.exception);
        })

}
}

I knew that the file transfer plugin didn’t work in the emulator. So, I ran the app using USB Debugging on my Android device. When I ran it, I got the “Success” alert. When I debugged it, the pathToSaveTo points to: file:///data/data/com.ionicframework.ionic2tutorial958766/files/abc.docx. However, I could not find com.ionicframework.ionic2tutorial958766 directory or file at all when browsing into the Android/Data folder in my device. Can anybody tell me what I did wrong?

Hmm, how are you trying to view the files on your device?
From past experience, I know that android keeps the file system on real devices pretty tight. So things inside of data/data/<app folder> tend to require permission not available on production OS.

Thanks for your response. When you said “require permission”, did you mean that the app cannot use /data/data/ or you cannot view what’s in it unless you do it from the app itself? I tried to view the files on my device by connecting my phone using USB cable to my laptop. And then I used Windows Explorer to view the “This PC\XT1094\Internal storage\Android\data” folder. I saw the folder for the other apps there. But I didn’t see one that contains the ID of my app. Does this mean that the files were not created properly by my app or the files could not be viewed this way? Thanks again.

Never mind. I think I found out the answer. It looks like the files are actually downloaded OK into my phone. My confusion was because I could not view it with Windows Explorer or ES File Explorer. I found out that you must ‘root’ your android device in order to view this folder. Thanks for your answer.

Can you explain what you mean by ‘root’ your app? Some code perhaps?

More info:
Im stuck on not being to locate my file after I have donwloaded it. I can view it in the adb shell when I save it to window.cordova.file.dataDirectory, but when I move it to window.cordova.file.externalRootDirectory, I can no longer find it.

I would like the user to see the file in their file explorer (Android users only), and open the file.

Edit:

Solved it with this:

return Observable.of(fileTransfer.download(url + this.getUpdateUrl, window.cordova.file.externalRootDirectory + ‘Download/’ + ‘update_file_name’, true))

    .map((entry: any) => {
        console.log('download complete: ' + JSON.stringify(entry))
        return entry
    })
    .catch((error) => {
        console.log(error)
        return error
        // handle error
    });`