Giter Site home page Giter Site logo

henry-hiles / media_store_plus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snnafi/media_store_plus

0.0 0.0 0.0 3.19 MB

To use Android MediaStore API in Flutter

Home Page: https://pub.dev/packages/media_store_plus

License: MIT License

Kotlin 32.38% Dart 67.62%

media_store_plus's Introduction

media_store_plus

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

Motivation

From API level 30, we have to use Scoped Storage to write file. 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, Download folders by MediaStore without any kinds 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 permission 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 write in any folder with/without storage permission other than app data folder!

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

So, only solution to use platform channel for this. Actually, this issue lead me to create this media_store_plus plugin.

Usage

You can read, write, edit, 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 these mentioned above, by file picker with this plugin. Again when you will try to read, edit or delete a file that is not created by your app, it will request permission from user for that task automatically.

You can read the full documentation from here. You can also check the example app for implementation. Reading the plugin's source code also help 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.1

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>

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 rooms 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

media_store_plus's People

Contributors

snnafi avatar henry-hiles avatar douglasiacovelli avatar refi64 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.