v0.0.3
android_package_installer
一個用於從 APK 檔案安裝 Android 套件的 Flutter 插件。此插件使用 Android Package Installer,並需要最低 API 級別版本 21。
26喜歡 5300近 30 天下載160Pub 分數
Android
Flutter Android 包安裝程式外掛
{"sdk":"flutter"}^2.1.8{"sdk":"flutter"}^5.0.0以下為英文專案原文快照,最新內容請造訪 GitHub。
A Flutter plugin for installing Android package from apk file. Plugin uses Android Package Installer and requires minimum API Level version 21.
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.
<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>
<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>