0

I try to do "Open install dialog" from "Quick Examples" of https://github.com/pwlin/cordova-plugin-file-opener2 in ionic4

This is my code:

Imports:

import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { FileOpener } from '@ionic-native/file-opener/ngx';
import { File } from '@ionic-native/file/ngx';

Download and open a file:

const fileName = 'last.apk';
const fileMime = 'application/vnd.android.package-archive';

//const fileName = 'last.pdf';
//const fileMime = 'application/pdf';

const downloadLink = me.settings.api.bin + fileName;

const basePath = me.file.externalDataDirectory; //dataDirectory, externalApplicationStorageDirectory
const downloadPath = 'apk';

me.file.createDir(basePath, downloadPath, true).then(function(link) {

    const savePath = basePath + downloadPath + '/' + fileName;
    const fileTransfer: FileTransferObject = me.transfer.create();

    fileTransfer.download(downloadLink, savePath).then((entry) => {
        me.fileOpener.open(entry.toURL(), fileMime)
            .then(() => console.log('File is opened'))
            .catch(e => console.log('Error opening file', e));
    }, (err) => {

    });

});

It works fine, the PDF is downloaded and opened.

Fails with APK, file is downloaded successfully and file opener say "File is opened" but installation dialog never appears on window, what is wrong?

David
  • 1,116
  • 3
  • 18
  • 32

1 Answers1

2

I found the solution, add this lines on config.xml

<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</config-file>
David
  • 1,116
  • 3
  • 18
  • 32