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.