shared_storage 0.2.0 copy "shared_storage: ^0.2.0" to clipboard
shared_storage: ^0.2.0 copied to clipboard

discontinued
outdated

๐Ÿ“ Flutter plugin to get Android shared folders like DCIM, Downloads, Video, Audio. Works with Android 4.1 (API Level 16+)

Shared Storage Flutter Plugin #

pub package

Plugin to fetch Android shared storage/folders info

Notes #

  • Android Only
  • Alpha version
  • Supports Android 4.1+ (API Level 16+)
  • The targetSdk should be set to 31

Features #

This plugin allow us to get path of top-level shared folder (Downloads, DCIM, Videos, Audio) using the following Android API's

/// Get Android [downloads] top-level shared folder
/// You can also create a reference to a custom directory as: `EnvironmentDirectory.custom('Custom Folder')`
final sharedDirectory =
    await getExternalStoragePublicDirectory(EnvironmentDirectory.downloads);

print(sharedDirectory.path); /// `/storage/emulated/0/Download`
/// Get Android [downloads] shared folder for Android 9+
final sharedDirectory =
    await getMediaStoreContentDirectory(MediaStoreCollection.downloads);

print(sharedDirectory.path); /// `/external/downloads`
  • Start OPEN_DOCUMENT_TREE activity to prompt user to select an folder to enable write and read access to be used by the Storage Access Framework API
/// Get permissions to manage an Android directory
final selectedUriDir = await openDocumentTree();

print(selectedUriDir);
  • Create a new file using the SAF API
/// Create a new file using the `SAF` API
final newDocumentFile = await createDocumentFile(
  mimeType: '	text/plain',
  content: 'My Plain Text Comment Created by shared_storage plugin',
  displayName: 'CreatedBySharedStorageFlutterPlugin',
  directory: anySelectedUriByTheOpenDocumentTreeAPI,
);

print(newDocumentFile);
  • Get all persisted [URI]s by the openDocumentTree API, from SAF API
/// You have [write] and [read] access to all persisted [URI]s
final listOfPersistedUris = await persistedUriPermissions();

print(listOfPersistedUris);
  • Revoke a current persisted [URI], from SAF API
/// Can be any [URI] returned by the `persistedUriPermissions`
final uri = ...;

/// After calling this, you no longer has access to the [uri]
await releasePersistableUriPermission(uri);
  • Convenient method to know if a given [uri] is a persisted uri ("persisted uri" means that you have write and read access to the uri even if devices reboot)
/// Can be any [URI], but the method will only return [true] if the [uri]
/// is also present in the list returned by `persistedUriPermissions`
final uri = ...;

/// Verify if you have [write] and [read] access to a given [uri]
final isPersisted = await isPersistedUri(uri);

Android API's #

Most Flutter plugins uses Android API's under the hood. So this plugin do the same, and to retrieve Android shared folder paths the following API's are being used:

๐Ÿ”—android.os.Environment ๐Ÿ”—android.provider.MediaStore ๐Ÿ”—android.provider.DocumentsProvider


Open Source

Copyright ยฉ 2021-present, Laks Castro.

Shared Storage is MIT licensed ๐Ÿ’–

59
likes
0
pub points
95%
popularity

Publisher

verified publisheralexrintt.io

๐Ÿ“ Flutter plugin to get Android shared folders like DCIM, Downloads, Video, Audio. Works with Android 4.1 (API Level 16+)

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter

More

Packages that depend on shared_storage