Open 4ntoine opened 2 years ago
PS. It works for isDynamic: true
, but i'd like to persist the access across app relaunches.
It looks like the following:
if (isDynamic) {
_uriString = selectedDirectoryUri;
_directory = makeDirectoryPath(_uriString!);
}
should be done independent of isDynamic
value.
What do you think?
Hi @4ntoine , You can achieve the mentioned use case using static call.
await Saf.getDynamicDirectoryPermission()
@jvoltci How do i get the path then? Also i need persistable permission
It looks like the following:
if (isDynamic) { _uriString = selectedDirectoryUri; _directory = makeDirectoryPath(_uriString!); }
should be done independent of
isDynamic
value. What do you think?
Interesting. Surely we can, let's improve a bit here and there.
Hey! just curious, is this your channel? saf featured in top 10
@jvoltci nope
@jvoltci How do i get the path then? Also i need persistable permission
You can get it by using again a static method call!
await Saf.getPersistedPermissionDirectories()
Hope it helps!
@jvoltci Thank you, will take a look tomorrow
@jvoltci i can't understand where is the bug, but the paths look strange.
As reported earlier, i use the "MyApp" directory in external storage root.
Then _saf!.getDirectoryPermission()
is called and the initialUri
="content://com.android.externalstorage.documents/tree/primary%3A%2Fstorage%2Femulated%2F0/document/primary%3A%2Fstorage%2Femulated%2F0%2FMyApp".
It's navigated in File manager correctly and i just click "Use this directory" and the selectedDirectoryUri
= "content://com.android.externalstorage.documents/tree/primary%3AMyApp".
I'd expect it to be not changed (as i haven't changed the dir), but URI is different!
As a result the selectedDirectoryUri != _uriString
is "true" and releasePersistableUriPermission
is called and false
returned.
Am i missing anything?
PS.
If i remove isDynamic
check as i suggested it works (i'm able to get the list of the files in the directory), but due to _directory = makeDirectoryPath(_uriString!)
i get "MyApp" as full path and some other functions (like Saf.getPersistedPermissionDirectories()
) return list of "MyApp" instead of "/storage/emulated/0/MyApp" (which is incorrect).
PPS.
I see you implemented Uri <-> String convertation yourself, how about using (or at least comparing with) existing "uri_to_file" pub?
also I have the issue,
Saf saf = Saf(path);
await saf.getDirectoryPermission(isDynamic: true);
var cachedFilesPath = await saf.cache();
for (String path in cachedFilesPath!) {
if (path.endsWith(images ? 'jpg' : 'mp4')) {
photos.add(File(path));
}
}
I'm using this codes to request directory permission and read the files inside the path, Its working fine. But My issue is its Always requesting the permission every time when I open the app. How to request permission only once if granted.
DID YOU FIND A WAY?
Check shared_storage as an alternate solution to this.
Its Always requesting the permission every time when I open the app. How to request permission only once if granted. Is there any solution for this?
path "/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses" bool? isGranted = await saf.getDirectoryPermission(isDynamic: true);
Did anybody found a way ? Permission does not persist after relaunch
Its Always requesting the permission every time when I open the app. How to request permission only once if granted. Is there any solution for this?
path "/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses" bool? isGranted = await saf.getDirectoryPermission(isDynamic: true);
Did you find a solution ?
Its Always requesting the permission every time when I open the app. How to request permission only once if granted. Is there any solution for this? path "/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses" bool? isGranted = await saf.getDirectoryPermission(isDynamic: true);
Did you find a solution ?
@ATOISABOY similar feature is implemented at https://github.com/krupal4/StatusSaver using this package.
@dhaval-k-simformsolutions @4ntoine @Ruwasoft @ashwin066 @Jaganvk29
Here is the code i use:
Then i check the permission:
Before the file manager is shown the uri is
content://com.android.externalstorage.documents/tree/primary%3A%2Fstorage%2Femulated%2F0%2FMyApp
. The file manager is shown and i just click "Use this directory" and tap "Allow". After the file manager is shown the uri becomescontent://com.android.externalstorage.documents/tree/primary%3AMyApp
(selectedDirectoryUri
value).So the following is
true
and the permission is released:As a result, no permission is granted.