搜索插件、代码仓与 APP 分类

插件详情v2.1.0

install_plugin

一个用于在 Android 上安装 APK 的 Flutter 插件;在 iOS 上使用 URL 跳转到应用商店。

AndroidiOS
近 30 天下载
1.3万
喜欢数
79
Pub 分数
150

安装插件

flutter pub add install_plugin

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

install_plugin 是一个 Flutter 包,可使 Android 应用直接安装 APK 文件,从而实现无缝的应用更新或安装。对于 iOS,它会通过提供的 URL 将用户重定向到 App Store,确保符合 Apple 的分发政策。专为应用更新场景设计,该插件简化了交付新版本的过程,无需用户手动从外部来源下载。该插件支持 Android 和 iOS 平台,为管理应用安装工作流提供跨平台解决方案。可通过 pub.dev 轻松集成,并包含开源代码以保证透明度和可定制性。

适合场景

  • 应用自动更新功能
  • 直接在Android上安装APK
  • 重定向 iOS 用户至 App Store
  • 捆绑应用分发
  • 应用内更新提示
  • 离线应用安装

主要特点

  • Android APK安装
  • iOS 应用商店重定向
  • 跨平台支持
  • 通过 pub.dev 的简单集成
  • 开源代码库
  • 基于URL的iOS导航

适合对象

  • 开发自更新应用程序的开发者
  • 需要离线安装的应用
  • 分发自定义 APK 的项目
  • 带有应用内更新逻辑的移动应用程序
  • 需要透明更新机制的团队

使用建议

  • 需要 Android 权限以安装 APK
  • iOS 仅支持 App Store 重定向
  • APK安装需要Android上的用户权限
  • 不适合用于官方 App Store 提交
  • 仅限 Android 和 iOS 平台
  • 来自不可信APK源的安全风险

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

install_plugin

Build Status pub package license

We use the install_plugin plugin to install apk for android; and using url to go to app store for iOS.

Usage

To use this plugin, add install_plugin as a dependency in your pubspec.yaml file. For example:

dependencies:
  install_plugin: '^2.1.0'

iOS

Your project need create with swift.

Android

You need to request permission for READ_EXTERNAL_STORAGE to read the apk file. You can handle the storage permission using flutter_permission_handler.

 <!-- read permissions for external storage -->
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

In Android version >= 8.0 , You need to request permission for REQUEST_INSTALL_PACKAGES to install the apk file

<!-- installation package permissions -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

In Android version <= 6.0 , You need to request permission for WRITE_EXTERNAL_STORAGE to copy the apk from the app private location to the download directory

<!-- write permissions for external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Example

install apk from the internet

  _networkInstallApk() async {
    if (_progressValue != 0 && _progressValue < 1) {
      _showResMsg("Wait a moment, downloading");
      return;
    }

    _progressValue = 0.0;
    var appDocDir = await getTemporaryDirectory();
    String savePath = appDocDir.path + "/takeaway_phone_release_1.apk";
    String fileUrl =
        "https://s3.cn-north-1.amazonaws.com.cn/mtab.kezaihui.com/apk/takeaway_phone_release_1.apk";
    await Dio().download(fileUrl, savePath, onReceiveProgress: (count, total) {
      final value = count / total;
      if (_progressValue != value) {
        setState(() {
          if (_progressValue < 1.0) {
            _progressValue = count / total;
          } else {
            _progressValue = 0.0;
          }
        });
        print((_progressValue * 100).toStringAsFixed(0) + "%");
      }
    });

    final res = await InstallPlugin.install(savePath);
    _showResMsg(
        "install apk ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
  }

install apk from the local storage

  _localInstallApk() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();
    if (result != null) {
      final res = await InstallPlugin.install(result.files.single.path ?? '');
      _showResMsg(
          "install apk ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
    } else {
      // User canceled the picker
      _showResMsg("User canceled the picker apk");
    }
  }

Go to AppStore , example appStore url : https://itunes.apple.com/cn/app/%E5%86%8D%E6%83%A0%E5%90%88%E4%BC%99%E4%BA%BA/id1375433239?l=zh&ls=1&mt=8

  _gotoAppStore(String url) async {
    url = url.isEmpty ? _defaultUrl : url;
    final res = await InstallPlugin.install(url);
    _showResMsg(
        "go to appstroe ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
  }

所属分类

源码仓库

使用此插件的项目