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

插件详情v0.0.3

android_package_installer

一个用于从 APK 文件安装 Android 包的 Flutter 插件。该插件使用 Android Package Installer,需要最低 API 级别版本 21。

Android
近 30 天下载
7860
喜欢数
27
Pub 分数
160

安装插件

flutter pub add android_package_installer

插件介绍

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

一个 Flutter 插件,允许在应用内直接安装 Android APK 文件。它利用 Android 包安装程序 API,需要最低 API 级别为 21。这使开发者能够安全高效地实现应用内更新或侧载功能。该插件专为 Android 设计,并与 Flutter 应用无缝集成。它简化了安装包的过程,无需依赖外部工具或系统意图。

适合场景

  • 应用内应用更新
  • 侧载 APK 文件
  • 企业应用中的自动化部署
  • 通过直接下载 APK 更新应用

主要特点

  • 使用原生 Android 包安装程序
  • 支持 API 级别 21+
  • 简单的 Flutter 集成
  • 安全安装工作流程
  • 无需外部意图

适合对象

  • 开发更新系统的开发者
  • 企业应用开发者
  • 需要 APK 安装的应用
  • 针对 Android 的 Flutter 应用

使用建议

  • 仅适用于 Android
  • 需要 API 级别 21 或更高版本
  • 需要用户权限才能安装
  • 限制为 APK 文件格式
  • 不支持 iOS

原始 README

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

android_package_installer

A Flutter plugin for installing Android package from apk file. Plugin uses Android Package Installer and requires minimum API Level version 21.

Using

import 'package:android_package_installer/android_package_installer.dart';

  int? statusCode = await AndroidPackageInstaller.installApk(apkFilePath: '/sdcard/Download/com.example.apk');
  if (statusCode != null) {
    PackageInstallerStatus installationStatus = PackageInstallerStatus.byCode(statusCode);
    print(installationStatus.name);
  }

To install the Android package the application will need permissions. You can use the permission_handler package to request them.

Setup

  1. Add the permissions to your AndroidManifest.xml file in <projectDir>/android/app/src/main/AndroidManifest.xml:
    • android.permission.REQUEST_INSTALL_PACKAGES - required for installing android packages.
    • android.permission.READ_EXTERNAL_STORAGE - required to access the external storage where the apk file is located.
<manifest xmlns:tools="http://schemas.android.com/tools" ...>

  <!-- ADD THESE PERMISSIONS: -->
  <!-- Android 10 Permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <!-- Android 11+ Permissions -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage"/>
  
  <application ...>
    <activity ...>

      ...

      <!-- ADD THIS INTENT FILTER -->
      <intent-filter>
        <action android:name="com.android_package_installer.content.SESSION_API_PACKAGE_INSTALLED"/>
      </intent-filter>
    </activity>

    <!-- ADD THIS PROVIDER -->
    <provider
      android:name="androidx.core.content.FileProvider"
      android:authorities="${applicationId}"
      android:grantUriPermissions="true">
      <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths"/>
    </provider>
  </application>
</manifest>
  1. Check external path in your custom paths file. If it doesn't exist, create it in <projectDir>/android/app/src/main/res/xml/file_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.1.8

源码仓库

使用此插件的项目