Ionic 2 - FileOpener open an apk file from download path


#1

I download apk file from my server and get the native path after it downloaded and saved on the app dir
then i try to open it with FileOpener but get this error:
EXCEPTION: Uncaught (in promise): Failed to find configured root that contains /data/data/com.ionicframework.power10fs142463/files/Power10_FS_0.2.apk

code:

fileTransfer.download(url, savePath).then((entry) => {
  const nativePath = entry.toURL();
  FileOpener.open(
     nativePath,
     'application/vnd.android.package-archive'
   );
});

#2

Did any get solution? Even I have same issue.


#3

Yes this solves by changing the save path from “File.dataDirectory” to > File.externalDataDirectory.

Example code:

const savePath = File.externalDataDirectory + '/newVersions/' + 'AppName_' + this.newVersionNumber.toString() + '.apk';

fileTransfer.download(url, savePath).then((entry) => {
  const nativePath = entry.toURL();
FileOpener.open(
  nativePath,
  'application/vnd.android.package-archive'
).then((success) => {
  console.log('success: ', success);
}, (err) => {
  console.log('err: ', err);
});
}

#4

Thank you @avishai_peretz_dev for you code.
But when the device have not a SD Card, your code run ?

Thank You in advance. :slight_smile:


#5

sure its not go to sd card


#6

this give me popup of “There was a problem while parsing the pakage”