File I/O

1418 views
Skip to first unread message

patrick Doyle

unread,
Dec 5, 2012, 7:17:22 AM12/5/12
to ai...@googlegroups.com
Hey everybody

So as we all know, there is no direct way to read/write files to the sdcard via AI...

I have really been searching high and low for a solution to this problem and even considered re-writing the whole app in Eclipse.
Then I learned how to run a non AI app from an AI app using Activity Starter.

This was really a big relieve for me seeing that the app is really big and I do not feel like learning in depth Java at this stage.
I created a small activity in Eclipse that takes user input from a TextBox and writes the input to the sd card in a BTN_Click event.

But, now the problem comes in, I cant seem to get data that was sent from the AI app in the Eclipse app. the app just crashes.
I feel like i am very close to the solution, but i am clearly missing something silly.

Maybe we can all put our heads in one hat and work this out?

If anybody would like to see the code let me know.

Regards,
Patrick

Gary

unread,
Dec 5, 2012, 8:52:40 AM12/5/12
to ai...@googlegroups.com
!!!


I really really want to get file i/o working better.

The short answer to your specific question.
Set ExtraKey to APP_INVENTOR_START and ExtraValue to the text you want to pass.

Look at the (poorly documented - sigh) activity starter here http://sites.jsoft.com/rm/home/fb/as
both the mulitpicker and the file i/o examples pass text into the Android activity.


And because it is good to be more complete. Nowdays I am not sure if file i/o is a good thing. I like Fusion Tables and there are other ways to do what we use file i/o to do. If you give some details about what you want file i/o for, you will get input.

AND

I am working on file i/o using Activity Starter. How do you want to put our heads into one hat?

Gary






patrick Doyle

unread,
Dec 5, 2012, 9:08:07 AM12/5/12
to ai...@googlegroups.com
Well, I want to use the file i/o to store important data on the sd card so i can be retrieved via USB to a pc later on.

Unfortunately Fusion Tables and Google Spreadsheet wont work, because you need to have a data connection active 
for that and where my app will be used there wont always be signal...

I will try and use the ExtraKey you provided.

Thanks :) 


patrick Doyle

unread,
Dec 5, 2012, 9:17:09 AM12/5/12
to ai...@googlegroups.com

Nope, That ExtraKey doesn't work either.

When I run the AI app and select the button that launches the I/O app, the app just say "unfortunately, app has stopped working."
It seems like it has got something to do with this piece of code:

 Bundle extras = getIntent().getExtras();
        if (extras != null) {
                buf = extras.getString("buf");                
                fn = "filename.txt";     //getIntent().getData().toString();
             
As soon as I use getIntent().

Maybe I am sending the data wrongly from AI.
This is how i have my ActivityStarter set: 
Class: tlc.savetosd.savetosd
Package: tlc.savetosd
ExtraKey: APP_INVENTOR_START
ExtraValue: this is some test text



Gary

unread,
Dec 5, 2012, 12:44:22 PM12/5/12
to ai...@googlegroups.com
Try

buf = extras.getString("APP_INVENTOR_START");

I am out most of the rest of the day. sigh

Gary

patrick Doyle

unread,
Dec 6, 2012, 4:03:54 AM12/6/12
to ai...@googlegroups.com
I'VE GOT IT!!!!

who wants a little code snippet of what I've done?


Dennis A.

unread,
Dec 6, 2012, 5:05:16 AM12/6/12
to ai...@googlegroups.com
ok.. I would..

Gary

unread,
Dec 6, 2012, 6:11:21 AM12/6/12
to ai...@googlegroups.com
Hmmm

How best to document? Where to put the documentation and the source?

Post the Java and attach the source to the App Inventor source here?

Congratulations!!!

Gary

patrick Doyle

unread,
Dec 6, 2012, 7:10:49 AM12/6/12
to ai...@googlegroups.com
OK...

so here is what I have done:

Scenario:
I have a list that needs to be saved to SD card for retrieval via USB at a later stage.

App Inventor side of the solution:

1. You need an Activity starter that will launch the app that writes the data in a text file on the sd.
2. You need the package name of the "Eclipse" app.
3. You need the Class name of the Class that is being used to write the file.
4. You need a string to pass to the "Eclipse" app
5. You need to set an ExtraKey (has to be the same as in Eclipse)
6. You need to set an ExtraValue (any string)

Eclipse side of the solution:

I attached a text file with the Java code

If you all can wait a few hours I will post a full demo with app inventor blocks :)




savetosd.txt

Damien

unread,
Dec 12, 2012, 10:37:32 AM12/12/12
to ai...@googlegroups.com
Hi Patrick,

I am trying to achieve the same thing save the users data to the SD Card, ideally a local spreadsheet (in case of no Internet connection) but could work around a text file if that is not possible.

I have tried to follow your steps and have used the savetosd.txt and attached it as an asset within the APK.

I have looked at the example and I have populated the activity starter with the following data fields:

ACTION: android.intent.action.VIEW

ACTIVITY CLASS: tlc.savetosd.Savetosd

ACTIVITY PACKAGE: package tlc.savetosd

DATA TYPE: application/txt

DATA URI: file:///mnt/sdcard1/savetosd.txt (I have also tried file:///android_asset/savetosd.txt and file:///mnt/sdcard1/savetosd.txt)

EXTRA KEY: APP_INVENTOR_START

EXTRA VALUE: Yippee


When I push the button to start the activity I get "error 601: No corresponding activity found".  I have saved the java text file to my SD Card separately as a file and attached as an asset within the APK.

Could someone please let me know what I am doing wrong.

Kind regards

Damien

Taifun

unread,
Dec 12, 2012, 11:59:44 AM12/12/12
to ai...@googlegroups.com
Patrick provided the source of a Java apk, you have to create a Java apk first to be able to use it.
I also played around with Patrick's example and documented what I did here: http://puravidaapps.com/savetosd.php
Probably that helps...
Taifun
puravidaapps.com

Taifun

unread,
Dec 19, 2012, 6:49:45 PM12/19/12
to ai...@googlegroups.com
and now with Version 2 you can configure the target directory and in case the directory does not exist it will be created: http://puravidaapps.com/savetosd.php
Taifun
puravidaapps.com

Scott Ferguson

unread,
Dec 31, 2012, 4:36:28 PM12/31/12
to ai...@googlegroups.com
Nice!
---sfs

luca scandelli

unread,
Jan 8, 2013, 5:37:56 PM1/8/13
to ai...@googlegroups.com
thank you a lot (and of course to Patrick!)

patrick Doyle

unread,
Jan 14, 2013, 4:38:40 AM1/14/13
to ai...@googlegroups.com
Hey All.

I am very happy that this post helps you all. It gives me a tingling feeling of excitement every time I can help somebody out :)

Please feel free to contact me for any more help on any problems, I will gladly help where possible :)

Regards

Patrick Doyle

Jason Padovani Ginies

unread,
Jan 14, 2013, 8:54:15 AM1/14/13
to ai...@googlegroups.com
I think this application is very interesting. I tried however trying to install this on Android version 2.1 and the device says 'Problem parsing the package'. For which versions is this method compatible please?

Regards,

Jason

Taifun

unread,
Jan 14, 2013, 9:23:31 AM1/14/13
to ai...@googlegroups.com
You get this error because I used min sdk version 8 which is Android 2.2... Sorry about that.
But most probably this also works for Android 2.1, you only have to build everything again with a smaller sdk version...
The sources you can find here http://puravidaapps.com/savetosd.php
Taifun

Jason Padovani Ginies

unread,
Jan 14, 2013, 11:17:10 AM1/14/13
to ai...@googlegroups.com
A bit over me perhaps. Would this work on a version of android later than the 2.2?

SparK

unread,
Feb 5, 2013, 2:46:13 AM2/5/13
to ai...@googlegroups.com
Hi All, 

I'm somewhat using this app comfortably now. Is there a way to install the apk file to the emulator though?

Kind regards,

Jason

Reply all
Reply to author
Forward
0 new messages