You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following is my flutter code to open media folder inside flutter. But it always redirect me to device path only after then I need to select folder manually like I need to go to "Android" then select "Media" folder to get acccess to it.
What is the way to direct get access to folder for "Android" > "Media"?
import 'package:flutter/material.dart';
import 'package:saf_util/saf_util.dart';
class MediaAccessRequestScreen extends StatefulWidget {
@override
_MediaAccessRequestScreenState createState() =>
_MediaAccessRequestScreenState();
}
class _MediaAccessRequestScreenState extends State<MediaAccessRequestScreen> {
final _safUtilPlugin = SafUtil();
var _status = '';
String makeUriString({String path = "", bool isTreeUri = false}) {
String uri = "Android/media/";
String base = "content://com.android.externalstorage.documents/tree/primary%3A";
String documentUri = "/document/primary%3A${path.replaceAll("/", "%2F").replaceAll(" ", "%20")}";
if (isTreeUri) {
uri = base + path.replaceAll("/", "%2F").replaceAll(" ", "%20");
} else {
var pathSegments = path.split("/");
var fileName = pathSegments[pathSegments.length - 1];
var directory = path.split("/$fileName")[0];
uri = base +
directory.replaceAll("/", "%2F").replaceAll(" ", "%20") +
documentUri;
}
return uri;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Saf example app')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
try {
debugPrint("makeUriString: ${makeUriString()}");
final dir = await _safUtilPlugin.pickDirectory(
writePermission: true, initialUri: makeUriString());
if (dir == null) {
return;
}
if (!context.mounted) {
return;
}
debugPrint('path selected : ${dir.uri}, ${dir.name}');
setState(() {
_status = 'success: ${dir.uri}, ${dir.name}';
});
} catch (err) {
setState(() {
_status = 'Error: $err';
});
}
},
child: const Text('Hello')),
SizedBox(height: 16),
Text(_status)
],
),
),
),
);
}
}
Let me know what I'm missing?
Thanks
The text was updated successfully, but these errors were encountered:
@mgenware
Following is my flutter code to open media folder inside flutter. But it always redirect me to device path only after then I need to select folder manually like I need to go to "Android" then select "Media" folder to get acccess to it.
What is the way to direct get access to folder for "Android" > "Media"?
Let me know what I'm missing?
Thanks
The text was updated successfully, but these errors were encountered: