搜尋套件、儲存庫與 APP 分類

套件詳情v0.0.3

android_package_installer

一個用於從 APK 檔案安裝 Android 套件的 Flutter 插件。此插件使用 Android Package Installer,並需要最低 API 級別版本 21。

Android
近 30 天下載
6340
喜歡數
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

原始碼儲存庫

使用此套件的專案