cordova-plugin-apkinstaller

Cordova Apk Installer Plugin.

Usage no npm install needed!

<script type="module">
  import cordovaPluginApkinstaller from 'https://cdn.skypack.dev/cordova-plugin-apkinstaller';
</script>

README

npm version

cordova-plugin-apkInstaller

このプラグインはAPKファイルからインストーラーを 立ち上げるためのプラグインです。
This plugin allows you to start the app installer.

Installation

$ cordova plugin add cordova-plugin-apkinstaller

Supported Platforms

Android only. (version 7.0.0 ~ )

How to use

Parameters

  • fileName: install apk file name (ex: android-sample.apk)
  • successCallback: A callback when success to start the installer.
  • errorCallback: A callback when occur errors.
apkInstaller.install(fileName, function(msg) {
    // Start the installer
}, function(error) {
    // Install error
});

Other

Shared directory
Shared directory setting is in file_paths.xml.
For details, please click here => FileProvider

<!-- platforms/android/res/xml/file_paths.xml -->
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="apkDirectory" path="/"/>
</paths>

Example

以下は、インストールボタンを押したときにAPKファイルを外部からダウンロードし、
ダウンロードしたAPKのインストーラーを立ち上げるサンプルです。
APKファイルのダウンロードはcordova-plugin-file-transfer等を用いてください。

ApkInstallerPluginSample

Click the INSTALL button.
top page

Downloading apk file...
download apk

Start the installer !
start the installer

var element = document.getElementById(id);

element.addEventListener('click', function() {

    // Apk download by cordova-plugin-file-transfer
    var fileTransfer = new FileTransfer();

    // Get cordova file data directory (app sandbox directory)
    //  > file:///data/user/0/io.cordova.apk.installer.sample/files/
    var sandBoxDirectory = cordova.file.dataDirectory;

    // Apk download path
    var apkUrl = 'http://example.com/sample.apk';

    // Get file name from apk url;
    var fileName = apkUrl.match(/[^/]+$/i)[0];

    fileTransfer.download(
        apkUrl,
        sandBoxDirectory + fileName,
        function(entry) {
            // Install app
            apkInstaller.install(fileName, function(msg) {
                // Start the installer
            }, function(error) {
                // Install error
            });
        },
        function(error) {
            // Download error
        },
        false, {}
    );

}, false);