2

I am developing an android application..i want to import data from csv file into a list in appinventor..1 method is to upload that csv file online and then extract data from it..is there a way by which i can keep that csv file in sd card and get data from it? If I upload that csv file and then extract data from it, then what is the shortest and simplest way??Any examples??

user1518793
  • 135
  • 2
  • 2
  • 13
  • [please also take a look how stackoverflow works](http://stackoverflow.com/faq#howtoask): in case the question is answered, mark the accepted answer by clicking on the check box outline to the left of the answer to mark it as answered – Taifun Nov 09 '12 at 17:09

2 Answers2

0

Normally this is not possible with App Inventor, but there is a trick to read a text file from SD card: you can use App Inventor together with embedded HTML/JavaScript, see an example here: http://puravidaapps.com/read.php

Meanwhile I prepared another example which imports a multiline csv file stored as asset in App Inventor on first run of the app and stores it as list of lists in TinyDB. Please find it here: http://puravidaapps.com/importCSV.php

Taifun
  • 6,165
  • 17
  • 60
  • 188
-2

Yes, you can store a csv file in sdcard and write a small parser to parse csv file to construct your list. If the file is available somewhere remotely, I recommend to download the file first and then parse the file.

Answer from here -> Get and Parse CSV file in android

  //--- Suppose you have input stream `is` of your csv file then:

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
    String line;
    while ((line = reader.readLine()) != null) {
         String[] RowData = line.split(",");
         date = RowData[0];
         value = RowData[1];
        // do something with "data" and "value"
    }
}
catch (IOException ex) {
    // handle exception
}
finally {
    try {
        is.close();
    }
    catch (IOException e) {
        // handle exception
    }
}

and may be have a look at this too,

http://code.google.com/p/secrets-for-android/source/browse/trunk/src/au/com/bytecode/opencsv/CSVReader.java

Community
  • 1
  • 1
VendettaDroid
  • 3,131
  • 2
  • 28
  • 41
  • this might be a good answer, but not for that question, which is about App Inventor http://www.appinventor.mit.edu/ – Taifun Aug 28 '12 at 21:50