Android Question Copy CSV file from Download folder

stevetheframe

Member
Licensed User
Longtime User
I have an App on Google Play where the user can update the pricing information by downloading a csv file and then importing it into the App (from the Download folder). All has been well until Google Play has forced me to target SDK 30.
I have changed from using a simple FileDialog to code based on the ExternalStorage class. This works well until I try it on Android 11 where, although I can see the file(s) in Download, there is a message "Can't use this Folder. To protect your privacy, choose another folder."
The odd thing is that if I put the file in the "Pictures" folder I can import it from there.
Am I being too optimistic trying to use the ExternalStorage class when I need to use something else?
 

drgottjr

Expert
Licensed User
Longtime User
understanding why certain design decisions were made will help to suggest some remedies.

why does the user have to do any of this? (why not the app itself?)
why isn't the file downloaded directly to the app? (all my file updates do this.)
how, exactly is the download carried out?

and to confirm your finding: you can't use the downloads folder on android 11.

also, after figuring out how you'll handle life under sdk30 (and beyond), do you have a plan in place to migrate current users to sdk30?
 
Upvote 0

stevetheframe

Member
Licensed User
Longtime User
understanding why certain design decisions were made will help to suggest some remedies.

why does the user have to do any of this? (why not the app itself?)
why isn't the file downloaded directly to the app? (all my file updates do this.)
how, exactly is the download carried out?

and to confirm your finding: you can't use the downloads folder on android 11.

also, after figuring out how you'll handle life under sdk30 (and beyond), do you have a plan in place to migrate current users to sdk30?
Thanks for your reply.
At present the csv file is on a supplier's website (it could be any relevant supplier), the user goes to that website and downloads the file, therefore it ends up in the Download folder (which seems irrelevant now that it cannot be used).
As Google Play now insist that APKs must target SDK30 I cannot even maintain the App without addressing this problem.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
let me re-phrase: is there actually a reason why the user could not acquire the file through the app?
it could be almost trivial to implement. with no need for the download folder (even if it were available).

it is still not clear to me why the user has to do anything; the app could do it.

i understand what is being done. i'd like to know why it must continue to be done the same tortuous way.

if the user did not have to go to some website and download some file to some folder and then move
the file from that folder to the app, would you be open to bypassing all that? or is there some constraint
which requires things to be done in this circuitous fashion? is okhttputils an option for you?
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Let me put it in another way, if it helps.

@stevetheframe we advise as follows,
  1. get the site url from user
  2. use okhttp.. to download the csv
  3. put the csv in dirinternal etc.
  4. read the csv and continue as rest.
Hope it helps.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
my english she is weak. thank you.
 
Upvote 0

stevetheframe

Member
Licensed User
Longtime User
let me re-phrase: is there actually a reason why the user could not acquire the file through the app?
it could be almost trivial to implement. with no need for the download folder (even if it were available).

it is still not clear to me why the user has to do anything; the app could do it.

i understand what is being done. i'd like to know why it must continue to be done the same tortuous way.

if the user did not have to go to some website and download some file to some folder and then move
the file from that folder to the app, would you be open to bypassing all that? or is there some constraint
which requires things to be done in this circuitous fashion? is okhttputils an option for you?
Thanks for the reply. Perhaps I'm over-thinking the problem.
The App won't know which website to go to (potentially hundreds worldwide, most of which I wouldn't know of). Also needs to be able retrieve the file from an email attachment.
I'll look into okhttputils (thanks for the pointer) it's an area I haven't used in the past.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the app doesn't have to know the location initially. eg, the user could tell it at some point. the user could even change it at some later point, if needed.

you can still use the download folder, you know. just not the way you're using it. the user goes to the download folder and "shares" the file with your app. easy peasy. ditto with an email attachment (which you didn't tell us about before). instead of the app's "pulling" the file from the download folder, the download folder "pushes" the files into the app. this is how google wants things done. so, in addition to looking into okhttputils, there is also sharing to research. we all use both of them, so there is no dearth of possible helpers for you (in the event the good lord takes me before i can reply further in the matter)

there are several options, but we ( actually, me) need to have the full picture.
 
Upvote 0

stevetheframe

Member
Licensed User
Longtime User
You are being so helpful, thanks.
To fill you in about the app - It is a pricing calculator for picture framers (I am a picture framer during the day). One way it can calculate a price is by looking up the moulding data on the csv file. Suppliers can issue a file, or the user can generate their own on a pc, or modify the supplier's by editing the csv. This can (could) then be imported into the app. I purposely do not want the app to have to use an internet connection when it is being used to issue prices.
I like the idea of the download folder pushing the file (instead of the app pulling it). If you know of a tutorial or forum post about this, please point me towards it.
I'm still amazed that google will allow you to pull file from the pictures folder, but not the download folder. But then I've shown too much of my ignorance!
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i want to study what you've described.
there are plenty of file sharing links here. see little search box above right. i am happy to explain how sharing is done. i use it successfully on a number of my apps. but first i need to consider what you've just written.
more important, however, is for you to visualize how you're going to migrate your users to sdk30. it's basically already too late to "migrate"; they have to be switched cold turkey, if that expression is used up your way. that is a big problem with no intermediate step. google has given us almost 2 years to prepare for this. steps they have provided have expired. how do you tell your users what they have to do with the data they already have? or does that even matter? unless you're going to contact your users individually with instructions, the only way to contact them is through an app update on play. how do you pull that off?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
so, no internet (inside the app) is the key. that would rule out any kind of file download within the app. unless, of course,
there were no other way - which is definitely not the case. you see? it only took 8 exchanges to get that out of you.:)

i'm liking file sharing as the way to go. the way it works is the download folder is actually an app. the app allows users
to share resources (files) in the folder with other apps. this is done through a manager or provider. basically android itself.
apps register to receive resources by statements in their manifest. you decide which type(s) of resources your app
wants to receive. you register it. when the user downloads his prices and saves them in downloads, he selects the file in the
folder. the little share icon appears, and if the user taps on the icon, a list a programs that can accept that type of file appears,
among them, your app. the user taps on your app, and your app does something with the file (eg, saves it locally or maybe
acts on its contents immediately without saving). as far as your app is concerned, you have to:
1) edit the manifest
2) make some changes to the activity_resume sub
3) in theory you may not have to change much else, assuming the app knows what to do when a csv file has been received.
all we're doing here is changing the way the file is received.

the download folder is a little different from, eg, the pictures gallery (as you have already observed); i don't want to promise you
something that isn't going to work. i'm testing with a dummy csv file that i put in the download folder to see what's involved in
pushing it into one of my apps.

a frame molding price market - who knew?! i'm guessing you must have a couple url's. let me have 1 so i can mimic the whole process.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
attached please find an example covering 3 different ways to allow your users to continue using the download folder as a target for the csv prices download. there is also a readme with it.

i've tested it; should work. it only deals with allowing users to store resources in the download folder and to access those resources under sdk30 and android 11. no other issues relating to your app's program flow were addressed, as i have no knowledge of it beyond what you have described.
 

Attachments

  • steve.zip
    10.6 KB · Views: 204
Upvote 0

stevetheframe

Member
Licensed User
Longtime User
Wow! I never expected such help.
I think method 3 is the way to go. It works and looks very similar to the way the App works at the moment.. I've tested it on an Android 7 device as well as 11.
If I use that method - will I need to add all the extra lines to the manifest?
I've attached an example of the csv file that the App uses. The user only needs to import a file when the supplier changes prices (hence the app itself doesn't need to be online). Although I'm sure you would find my code very "clunky", because I'm a framer I can produce an app that works in the way framers think (I can always tell if an app is written by a framer or a coder who has never framed anything) I also have a pc version (which does a lot more) on www.wessexpictures.com
 

Attachments

  • Mouldings (3).zip
    12.2 KB · Views: 172
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
so far, so good. i'll check the zip and the link. what is the name of your app? i should have asked before.

you can remove the intent filter stuff in the manifest. the only code you need is what's in activity_create sub in the example. content chooser is part of the phone library, so make sure to include that. and, normally, you would trigger the content chooser dialog by having the user click on a button (eg, "update prices").

now you have to break the news to your users. nobody likes having to do something a new way.
 
Upvote 0

stevetheframe

Member
Licensed User
Longtime User
so far, so good. i'll check the zip and the link. what is the name of your app? i should have asked before.

you can remove the intent filter stuff in the manifest. the only code you need is what's in activity_create sub in the example. content chooser is part of the phone library, so make sure to include that. and, normally, you would trigger the content chooser dialog by having the user click on a button (eg, "update prices").

now you have to break the news to your users. nobody likes having to do something a new way.
Thanks, all sorted out now. I've done as you suggested and made the code in your activity.create into a sub, which is called when the user presses "Import Mouldings File". I've also added some code to check that it is actually a csv file that has been selected.
I've checked it on Android 7 and 11.
As for breaking the news to the users - they've had to struggle with a file dialog up to now, this is so much better. The app website is www.theframerspricingapp.com.
I plan to upload the apk to Google Play tomorrow (just in case I think of something in the night!
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
good call on file check. i don't know what your content chooser dialog looks like, but mine does not inspire confidence. be ready for some blow-back from users. the original dialog was very simple. and you might want to keep in mind that "text/csv" is a legitimate mime type. since you choose files by mime type with the chooser, android should honor that, but it appears not to. you could check periodically; it might already be on a todo list. and you should be checking periodically anyway for changes in the os with each new version. i realize you don't do this for a living. good luck
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
If you download to the download folder, manually move the file to a different external folder, Google doesn't like Apps accessing the Download folder these days.
you're talking about something completely different. don't ruin it for the guy. he's not moving the file to a different external folder. please follow the thread.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
you're talking about something completely different. don't ruin it for the guy. he's not moving the file to a different external folder. please follow the thread.
drgottjr,
If you bothered to go to the link and look at my reply in it's entirety you would see that this precisely what the question is about.
The Link is the answer.

Moving the CSV from the Download Folder is NOT the answer.
It is a prerequisite to using the code at the end of the link. Google has limitations on Apps accessing the Download Folder.
Please read the complete answer.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the app doesn't access the download folder. your post may or may not have some bearing on a different problem. not the one in question.
 
Upvote 0
Top