Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Read Permission on PersistedUris #10

Closed
ankitparmar007 opened this issue Dec 1, 2021 · 26 comments
Closed

No Read Permission on PersistedUris #10

ankitparmar007 opened this issue Dec 1, 2021 · 26 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@ankitparmar007
Copy link

ankitparmar007 commented Dec 1, 2021

final selectedUriDir = await openDocumentTree();

selectedUriDir = content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses

final listOfPersistedUris = await persistedUriPermissions();

listOfPersistedUris [UriPermission(isReadPermission: false, isWritePermission: true, persistedTime: 1638318739830, uri: content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses)]

AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

**

  • compileSdkVersion 31
  • minSdkVersion 24
  • targetSdkVersion 31

**

@alexrintt
Copy link
Owner

Thanks for the issue, what kind of error are you having?

@alexrintt
Copy link
Owner

If I understood correctly, you don't need the read permission because currently the package always grants write permission

If you have the write permission we don't need the read permission

@alexrintt alexrintt added good first issue Good for newcomers invalid This doesn't seem right wontfix This will not be worked on and removed good first issue Good for newcomers labels Dec 1, 2021
@ankitparmar007
Copy link
Author

ankitparmar007 commented Dec 1, 2021

how can I read all the data from below given specific folder URI ?

Ex. content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses

@alexrintt alexrintt added documentation Improvements or additions to documentation question Further information is requested in triage Searching about and removed invalid This doesn't seem right wontfix This will not be worked on labels Dec 1, 2021
@alexrintt alexrintt added the good first issue Good for newcomers label Dec 2, 2021
@alexrintt
Copy link
Owner

Unfortunately this usecase is not currently supported, but I added this as a new feature request in #11, I'm planning to implement it on this weekend. Feel free to implement it by yourself if you want! Thanks for the issue.

@ankitparmar007
Copy link
Author

Thank you so much for your hard-work, But I don't know much about Java so I will use this package once you add support for read data.

Additional note
Please note that once we get the Persisted-Uri, Package should read all the files from the specific folder without user interaction.
So we can show all the data in App UI every time whenever user open up the app.

Once again Thank you so much for this amazing package :)

@alexrintt
Copy link
Owner

Hey @ankitparmar007! g'afternoon

Your usecase is to get large data sets? Like a folder with 1000+ files?

@ankitparmar007
Copy link
Author

ankitparmar007 commented Dec 7, 2021

Hey @LaksCastro

Glad to know that you are putting so much effort on this package :) Thank you so much for that !

Based on this URI

content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses

I am trying to read WhatsApp Statuses folder from this path => Android/media/com.whatsapp/WhatsApp/Media/.Statuses

So there is a possibility if user have business account or large user base in WhatsApp account then, Statuses may be available up-to 500 or more including images and videos.

As I can see that in 11 you have mentioned that you are facing issue for reading files which folder has so many files in it.

In my opinion you can limit the number of files reads up-to 1000 if you have no any other solution available currently.

Addition Note
I forget to mentioned in my last issues that openDocumentTree() will open the root directory and user have to manually navigate to this PATH like Android/media/com.whatsapp/WhatsApp/Media/.Statuses, would be appreciated if you add a property like this openDocumentTree(Path = "Android/media/com.whatsapp/WhatsApp/Media/.Statuses") so we can change Path parameter for easy navigation :)

If you need any other Help, For testing the package or live help on social media where we can easily communicate, I would really like to connect with you on you preferred social media account :)

@alexrintt
Copy link
Owner

Hey! Thanks for sharing your usecases.

Okay, I think I got your needs, this is about WhatsApp statuses and you need the initialDir. Is really useful to know what you need, to keep the focus on the priorities. Thanks for that.

Also, I think you'll need an way to export these files to another location, so maybe I also need to include some copy API in this next release.

  • So I'll finish the "database query" (Fix large data set issue)
  • Add initialDir param
  • Add copyTo API to allow you export the statuses

Btw, my Discord is always open laks#1712, thanks for using the package :)

@ankitparmar007
Copy link
Author

Ya I think You need to copy or cached all the files from URI specified folder to application cached folder for easy read I guess,
Also I have sent a friend request on Discord for effective communication.

@alexrintt
Copy link
Owner

alexrintt commented Dec 29, 2021

Hardcoded WhatsApp Status Media URI to use as initialUri when prompting the user

content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia/document/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses

Usage:

const kWhatsAppStatusUri = '...';

/// Prompt user with a folder picker (Available for Android 5.0+)
await openDocumentTree(initialUri: Uri.parse(kWhatsAppStatusUri));

@ankitparmar007
Copy link
Author

ankitparmar007 commented Dec 29, 2021

@lakscastro Good to see you working on package again :)
I have a quick tip for you that might help for caching data into temp directory of the user App using this open source package code https://pub.dev/packages/path_provider

Syntax to get application specific temp directory using path provider package
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;

Maybe You can store all the data given by openDocumentTree() method and store it in application specific cache folder(path given by tempPath) so app owner can easily clean up temp folder for storing more fresh data or can be deleted easily when there is no need of it.

Thank you so much again :)

@alexrintt
Copy link
Owner

yeah, of course, you can store the path wherever you want. You can also use a package like shared_preferences to store de data. Thanksful for the tip! =]

I mean that this specific path of the WhatsApp status is not available to get it from anywhere, so we need to hardcode it to use as initialDir

But be aware that this is the solution that I'm trying, you can send me any solutions that you think that will fill better our usecase!

@ankitparmar007
Copy link
Author

@lakscastro
I think shared_preferences cannot store images and videos, and we need to cache images and videos for instance, then application specific temp directory only be helpful for storing temporary data, in my opinion

Also end user won't pass any path to initialDir parameter, Only app developer can assign path to initialDir to open a specific folder, so in my opinion you don't need to hard-code WhatsApp Statuses Path.

If app Developer don't want to assign anything to initialDir then root directory will be open otherwise assigned path will be open using openDocumentTree().

If you didn't get it, no problem just let me know what you didn't understand, I will share video example on discord :)

@alexrintt
Copy link
Owner

alexrintt commented Dec 29, 2021

where do you'll get the assigned path?

@ankitparmar007
Copy link
Author

ankitparmar007 commented Dec 29, 2021

@lakscastro
/// Get permissions to manage an Android directory using shared_storage package
final selectedUriDir = await openDocumentTree();

print(selectedUriDir);

currently we can get WhatsApp Statues folder path by first opening root directory using openDocumentTree(); method and later user has to travel to this path /storage/emulated/0/Android/Media/com.whatsapp/WhatsApp/Media/.Statuses/

later openDocumentTree() method return the path for user selected folder and as you mentioned in above comment we can store same path in shared_preferences so user doesn't have to travel all the time and we can use same path for future use that's a good thing :)

But my point is can we read all the files from this path /storage/emulated/0/Android/Media/com.whatsapp/WhatsApp/Media/.Statuses/ without user interaction after we get the read permission from the user for the first time ?

below is an example for how we can read files

@override
void initState() {
  super.initState();
  var data = await openDocumentTree(initialUri: Uri.parse("content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia/document/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses%2FMedia"));
}

later we can show data in APP UI ???

also when calling openDocumentTree() method for the first time we can set initialDir path like this
final selectedUriDir = await openDocumentTree(initialDir="/storage/emulated/0/Android/Media/com.whatsapp/WhatsApp/Media/.Statuses/");

consider a point in this case we know the path already so we can directly assign path to initialDir parameter so user doesn't have to travel for the first time also and user can give the permission to read all the data from specified path :)

Hope you get my point :)

@alexrintt
Copy link
Owner

currently, path/to/something/will/not/work due the SAF API, they removed completely the File based API to work with files. Now we need to use the DocumentFile based API that is based on URIs

@ankitparmar007
Copy link
Author

ankitparmar007 commented Dec 29, 2021

Ohh that's a bad news :(
So you mean we can't use File App to get the user specified forlder which is inbuilt in almost every android phone ?

@alexrintt
Copy link
Owner

No, I mean that we just need to use SAF (Android 5.0+)

Most File APIs are now available in the DocumentFile API

Starting from new Android APIs (API Level 30+) File based APIs are not available anymore

@ankitparmar007
Copy link
Author

Bro Lets discuss on discord for effective and fast communication :)

@alexrintt
Copy link
Owner

Oh, of course

alexrintt added a commit that referenced this issue Dec 29, 2021
@alexrintt alexrintt removed the in triage Searching about label Dec 29, 2021
@ankitparmar007
Copy link
Author

@lakscastro hey bro
I think I have found a solution !
https://www.youtube.com/watch?v=1evcTdwZxwM
As show in this video we can read all files directly using uri for example

image uri would be like this
content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia/document/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses%2FMedia%2Fimage1.jpg

Decoded image uri looks like this
content://com.android.externalstorage.documents/tree/primary:Android/media/document/primary:Android/media/com.whatsapp/WhatsApp/Media/.Statuses/Media/image1.jpg

or for video uri looks like this
content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia/document/primary%3AAndroid%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses%2FMedia%2Fvideo1.jpg

so can you try like this once we select the directory using openDocumentTree() then this method should return LIST OF URIs for all the files located in selected folder

alexrintt added a commit that referenced this issue Jan 7, 2022
@jvoltci
Copy link

jvoltci commented Jan 30, 2022

@ankitparmar007 @lakscastro Hello folks. Does this package support the reading files from the Android folder using SAF DocumentTree yet? :)

@ankitparmar007
Copy link
Author

@jvoltci not fully ! This package needs more improvements

@jvoltci
Copy link

jvoltci commented Feb 2, 2022

Hey @ankitparmar007 ! Let's evolve this package because I researched and could not find any relevant package for this problem. Let's catch up, ping me on @jvoltci tweeter if are up!

@ankitparmar007
Copy link
Author

Hey @jvoltci Sorry to say but, I am not a twitter user ! you can connect with me on discord using this username ankit007#2133

@alexrintt alexrintt removed the documentation Improvements or additions to documentation label Apr 4, 2022
@alexrintt
Copy link
Owner

Closing this issue as resolved since all mentioned use-cases are now available in v0.4.x.

Please, you can always re-open this one or open a new issue. Any other bug-reports, questions or feature requests are always welcome!

Thanks for taking time to contribute to this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants