Hello,
When I download the the .csv file for first time I cann't find it in the phone and continue
Please help me.
Hello,
It is probably a file path issue:
Different components may require different paths. Use Do It in companion to check your paths, or display these in labels so you can see what is happening and where the files are going.
Note that API30 will not allow you to save files outside of the ASD, however, you should be able to then copy the file to specific shared folders. Search the community, there is plenty on this....
Thank you so muhc Tim for helping me.
Actually I am trying to download the specific file from google drive into my phone but after I close the apk and open it again it ask to download the same file agan and again from google drive. In fact that problem hasn't occured at all before in the same apk.
Let us start with the basics and build from there...
I will assume your are using the http://ai2.appinventor.mit.edu server, that your companion is up to date at version 2.62, and that you are using a device that creates the application specific directory (ASD):
/storage/emulated/0/Android/data/<packageName>/files
See this example that, on button press, downloads a csv file from google drive, save it to the ASD, then reads the file and displays it in a label.
CSVfromGDRead.aia (2.7 KB)
I have tested this in the companion app on Android 10.
Can you do this, and make it work, and perhaps this helps with your issue?
Hello Tim,
Thank you so much Tim, Can you please tell me how to download the file just in initialize app instead of click the button. I mean the download starting just when opening the app immediatlly without click button. In addition, I need to add one more button so that when I click it, it returns the values from csv file when disconnect the wifi instead of download that file again.
Good luck!
Put the blocks from Button1 into the Screen.Initialize
event.
Read the file (myFile.csv
) again with the File
component (since the file is already downloaded to the ASD).
Thank you so much Tim and Anke,
Now I understood that idea but when I apply this idea on my project I faced the same problem because in my project I have a list of items. For example I need to select one item from that list.
Please have a look to my project if can you help me.Thank you.
You do not appear to have made any changes to your blocks to accommodate the work already provided for you ? However....
I believe this does what you want:
- store files on google drive in the same folder
- store a list of files and file IDs in a google sheet
- download this list
- use a listview to select a file from the list
- download that file (if not already on device) and view contents
I set up a folder and three files on google Drive
I created a spreadsheet to store the filenames and the file IDs (I used a simple script to generate these)
function getcsvs() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Sheet1');
sh.clear();
sh.appendRow( ['Filename', 'FileID'] );
var folders = DriveApp.getFoldersByName('getcsvs')
var folder = folders.next();
var contents = folder.getFiles();
var file, name, id;
while(contents.hasNext()) {
file = contents.next();
name = file.getName();
id = file.getId();
sh.appendRow( [name,id] );
}
}
In the app blocks:
- On Screen Initialise I call down the contents of the spreadsheet
- the contents are set to an AI2 list
- a listview list is created from the filenames
- on selecting a filename, the corresponding file is downloaded, saved and opened (or just opened if already present on device)
Here is the aia
CSVfromGDReadv2.aia (4.2 KB)
Hello Tim,
I really appreicate for the great job you have done in trying to solve my problem. After I download the three files, I have disconnected the wifi to test it but this message comes up again I don't know why.
That is not the three files, that is the fetch of the data from the google sheet that fills the listview that you select the file to download from. I didn't put a no internet condition on this, which you will need to add.
I am so sorry Tim to bother you,
I mean that After completing downloading the three files in my phone, I want to select one of the file from the listviewer and read the content without the wifi but that message comes up again.
Yes, I will revert to using a csv file in the assets. As I understand the content of the file is unlikely to change much ?
It's a wonderful and miracle solution. Thank you thank very much for helping me Tim.
Good luck!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.