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

套件詳情v0.1.3

media_store_plus

要在 Flutter 中使用 Android MediaStore API,它透過 Flutter 支援所有 Android 版本的讀寫操作。

Android
近 30 天下載
2.4萬
喜歡數
91
Pub 分數
160

安裝套件

flutter pub add media_store_plus

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

media_store_plus 是一個 Flutter 套件,提供對 Android MediaStore API 的存取,可於所有 Android 版本上執行媒體檔案的讀取與寫入作業。它將 Flutter 與原生 Android 功能連結起來,讓開發者能透過系統的媒體儲存空間直接管理音訊、影片與影像檔。此套件專為與針對 Android 的 Flutter 應用程式無縫整合而設計,提供可靠的檔案處理功能,無需撰寫平台特定程式碼。支援常見的媒體作業,例如查詢、插入與更新媒體項目。

適用情境

  • 訪問設備媒體檔案
  • 管理照片和影片
  • 讀取和寫入媒體元數據
  • 與 Android 媒體庫整合
  • 建構媒體畫廊應用

主要特色

  • 跨版本 Android 相容性
  • 對媒體檔案的讀取與寫入支援
  • 原生 Android MediaStore 集成
  • Simple Flutter API
  • 不需要平台通道

適合對象

  • 僅限 Android 的媒體管理
  • 媒體畫廊應用
  • 從設備儲存空間匯入/匯出檔案
  • 需要直接存取 MediaStore 的應用

使用建議

  • 僅限 Android 平台
  • 需要適當的執行時權限
  • 可能需要處理權限請求
  • 依賴 Android SDK 版本相容性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

media_store_plus

To use Android MediaStore API in Flutter. It supports both read & write operations in every Android version through Flutter. It also requests appropriate permissions, if needed.

Motivation

From API level 30, we have to use Scoped Storage to write files. Though, we can read all files by direct path until API level 32, from API level 33 we need to use Scoped Storage for reading also.

We can write in DCIM, Pictures, Movies, Alarms, Audiobooks, Music, Podcasts, Ringtones, and Download folders by MediaStore without any kind of Storage permission. You can also read without any permission from these folders as long as the files are created by the app. But if we uninstall the app, and install it again, then, it will lose the read/write access for the files previously created by the app.

Again, we can read all files by requesting android.permission.READ_EXTERNAL_STORAGE permission until API level 32.From API level 33, it has no usage. Android introduces three specific permissions i.e. android.permission.READ_MEDIA_IMAGES, android.permission.READ_MEDIA_AUDIO & android.permission.READ_MEDIA_VIDEO to read audio, video & images.

But, we can't read other folders from API level 33 without requesting explicit permission for those folders.

Sum up, from Flutter there is no way to write in any folder with/without storage permission other than the app data folder!

Because, we can't use the MediaStore API from Flutter, that is required for writing, other than the app data folder. Again we can't request to read/write any specific folder using a file picker from Flutter.

So, the only solution is to use the platform channel for this. This issue led me to create this media_store_plus plugin.

Usage

You can read, write, edit, and delete in the DCIM, Pictures, Movies, Alarms, Audiobooks, Music, Podcasts, Ringtones, Download with this plugin. You can also request to read or write any specific folder other than those mentioned above, by file picker with this plugin. Again when you try to read, edit, or delete a file that is not created by your app, it will automatically request permission from the user for that task.

You can read the full documentation from here. You can also check the example app for implementation. Reading the plugin's source code also helps you in that case.

Getting Started

First, add media_store_plus as a dependency in your pubspec.yaml file.

dependencies:
  media_store_plus: ^0.1.3

Don't forget to flutter pub get.

Android Side

Edit the AndroidManifest.xml like this.

    <!-- required from API level 33 -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <!-- To read images created by other apps -->
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <!-- To read audios created by other apps -->
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <!-- To read vidoes created by other apps -->

    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE" <!-- To read all files until API level 32 -->
        android:maxSdkVersion="32" />

    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE" <!-- To write all files until API level 29. We will MediaStore from API level 30 -->
        android:maxSdkVersion="29" />

    <application
        ---------------------------
        android:requestLegacyExternalStorage="true"> 
        <!-- Need for API level 29. Scoped Storage has some issue in Android 10. So, google recommanded to add this. -->
        <!-- Read more from here: https://developer.android.com/training/data-storage/shared/media#access-other-apps-files-->
    </application>

You need to modify the proguard-rules.pro file as per this link. Because this plugin uses GSON internally.

Contribution

You can create issue(s) for any missing feature(s) that is relevant to this plugin. You can also help by pointing out any bugs. Pull requests are also welcomed

Status

This is an active project as MediaStore is the future of accessing files in Android. There's a lot of room to improve this plugin.

Support the package (optional)

If you find this package useful, you can support it by giving it a star.

Credits

This package is developed by Shahriar Nasim Nafi

所屬分類

依賴

依賴清單 2 項

  • meta^1.8.0
  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案