Giter Club home page Giter Club logo

cordova-plugin-apkinstaller's Introduction

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);

cordova-plugin-apkinstaller's People

Contributors

cigalecigales avatar partimer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.