|   FORUM      |     Tutoriales    |     KIO4 |      
   Start B4A (Basic4Android) App inventor 2 Arduino
   Elastix - VoIP Things of Windows Interesting Webs  Telecomunications

 


Nuevo concurso para España, Argentina, Brasil, Chile, Colombia, Ecuador, México, Perú y Portugal.

App Inventor 2
Programming mobile phones with Android 
by App Inventor 2 - Juan Antonio Villalpando

- Initiation Tutorial App Inventor 2 -

Return to tutorial index

____________________________

Storage


34.- Save and upload files. File.

ip34_file

- We can save text in a file and later retrieve them. Control File can only be saved as plain text.

- If the file name is sample.txt and we are in debug mode with MIT AI2 Companion, it is saved in the SD card, specifically in:

AppInventor/data/sample.txt,

ie: /mnt/sdcard/AppInventor/data/sample.txt

Also test file://mnt/sdcard/AppInventor/assets/sample.txt

- If the file name is sample.txt and aplication.apk is installed, it is saved to the SD card, specifically in the same folder where the application is. This is difficult to do with the Android File Browser. The advantage that the user will have difficulty copying, say that is something hidden.

- If the file name begins with / and aplicación.apk is installed, ie /sample.txt, it is saved in the root of the SD card, specifically in

/mnt/sdcard/ejemplo.txt.

To facilitate our study we keep the files with the bar / forward, this is /sample.txt

You can verify that the file is saved in that location using a File Manager, you have installed on your Android.

_________________
Design

_________________
Blocks

34B.- Now let's read the file.

ip34B_file_read

We extend the previous project.

We must put the same name as the file written above.

Get the file contents in the Label5.

_________________
Design

_________________
Blocks

- Notes:
- AppendToFile is used to add more texts at the end of a file.

- The file name is no need to carry extension, ie we can write the name of a file as an example, however it is better to finish it in .txt, sample.txt because otherwise when you try to open you might try starting with a PDF reader and an error.

- The element File put the MIT in May 2014 (nb133) until then had some complication save files.

How we could edit a text already created several lines?

- We call for ReadFrom File1 my_file, and when File1 GetText, puts it in a TextBox (You must have the property Multiline in Design).
After editing the text, we call for SaveFile File1 my_file with the text of TextBox.

_______________________________
34C.- Read an image file and plain text.

ip34C_file_read_image

- Let's work with image file and plain text.

- The study of this application tries to see how we place an image file and a text when the application is installed.

- Low and see the application in App Inventor and then Build the QR code for the .apk file and install it on your mobile. It is important that you study when installed.

- Let's see this picture:


puertoreal.gif

- And this text file: acueducto.txt

- Important: The file acueducto.txt have written it with Notepad. I kept it in Encoding: UTF-8 If I keep it with other coding, accents and eñes go as a black squares.

_________________
Design

- Button1, Image1, Label1, File1


- We upload: puertoreal.gif and acueducto.txt

- In the Properties Screen1 mark: Scrollable.

_________________
Blocks

Note that the image file: puertoreal.gif, is written directly.

Instead, the text is written with two bars at the beginning

//acueducto.txt

 

_______________________________
35.- TinyBD (I)

ip35_tinybd_simple


TinyDB, is a database that is in your mobile.


Simple example of TinyDB

It is save a person's name and age.


We write on name of a person, their age and click the Save Button.

Then we get name and age click the View Button.

The Delete Button deletes all data visible on the screen.

Tag
Name
Value
Age

Juan
22
Pedro
33
Luis
44

_________________
Design

_________________
Blocks

_______________________________
36.- TinyDB with List (II)

ip36_tiny_list

More complicated example of TinyDB

We have seen in the above example we can relate a tag with a value in a TinyDB, so we keep a Label with their respective value. Sending get the tag name value.

In this case, each value contains only one element, but let's assume that we want to save the Name, Age and City of a person (Name) in principle can not do it because each label contains only one value. But through a List we can make the value has several elements, the elements of the table.

Tag
Name

Value
Surname, Age, City

Juan
Perez 22 Cadiz
Pedro
Sanchez 33 Sevilla
Luis
Rodriguez 44 Jerez

We created a list called person.
Each time you press the Button1, delete the List. It is an auxiliary List, use it to enter three values ​​in each name. But it is not acumulative List that will keep all the names, so it is deleted upon arrival of each new name.

We enter the data in the TextBox person. TinyDB keep on the Label and its corresponding value that is the person List.

To see them.

Wrote in TextBox1, the name we want to see, this name will be the label. We get the value indicated on the tag, which will be the Surname, Age and City and inserted in the List.select the various elements of the list as its index.

_________________
Design

_________________
Blocks

We note that we can get the value of each element of people List by variable index .

_______________________________
37.- TinyDB (III)

ip37_tinybd_listview.aia

Example TinyDB more difficult.

_________________
Design

- Create a table called empty sites.

- When you press the Button1, we can switch between GPS coordinates to obtain or enter them manually. Will press to enter them manually.

- If we want to obtain GPS, GPS is enabled and the longitude and latitude in lockers.

_________________
Blocks

- When you press the Button2, it is checked whether the place name already exists in the list sites.
- If there is, remove it (ClearTag) of the Database list TinyDB and sites.

- Whether or not, stores the writing element in the TextBos1 on a tag of TinyDB and lockers of longitude and latitude, put them in another list of two elements and saves as a value in the TinyDB.

That is, keep the tag that would be the name of the town and two items using a list, which would be the longitude and latitude. Do not confuse this list of two elements with locations list, they are different.

location
(Tag TinyDB)
TextBox1
longitude, latitude
is introduced both in a list and stored.
TextBox2 and TextBox3
Grazalema -6.16; 35.21
Jerez -6.15; 35.24
Puerto Real -6.18; 36.52

- Also added to the List sites, the name of the sites.
- Also introduced into the ListView1 all elements of the places List.

 

- When you press the ListView1, we will have the elements previously saved ListView1.items = sites
- When you click an item in the ListView1, it is taken from the TinyDB the value of the selected item, this value, in turn, contains two parts, the one that would be the longitude and latitude.

- They are written in their TextBox appropriate. That is, the tag is the name of the selected item and value is the value of that element, which in turn contains two terms, since they were introduced by a list of two parts.

- Again, do not confuse the sites List, containing the names of places only and another List that has no name that contains the two coordinates in each of its elements.

- Each time the screen starts, take the tag of TinyDB and introduced into the places list.
The list elemenos of places, are introduced into the ListPicker.

- The Button3 use it to clean the entire database.

- The last item will last in the ListView1.

_______________________________
38.- TinyWebDB.

ip38_miniwebbd_simple

TinyWebDB, is a database that is on the Internet.

With TinyWebDB we can save the information on the web. App Inventor offers a learning aid MiniTinyDB: http://appinvtinywebdb.appspot.com/
so that they can rise to 1000 values ​​to your website. ( Other ) ( one more ) ( other )

These values ​​are shared by all users of App Inventor, so that when those values ​​are exhausted 1000 new arriving values ​​are overwritten.

You can create a custom database by the programmer with its own server, the more complicated as we see in this tutorial ...

http://appinventor.mit.edu/explore/ai2/custom-tinywebdb.html

It is this simple example we will introduce data states and their capitals. We keep it.

And then typing the name of the State and clicking the View button, we can see its Capital.

_________________
Design

Important:

In the ServiceURL property of TinyWebDB, should you set the website where the information is stored, in our example:

http://appinvtinywebdb.appspot.com

_________________
Blocks

In the database and its corresponding label value, for example is stored:

tag
Country

value
Capital

Spain
Madrid
Portugal
Lisbon
Italy
Rome

_______________________________
39.- MiniTinyBD with several fields.

ip39_tinywebbd_list

- In the above case we introduced a Tag and its respective Value. But in other cases we store a tag containing multiple values, for example:

Tag
Name

Value
Surname, Age, Country

Juan
Perez 22 Cadiz
Pedro
Sanchez 33 Sevilla
Luis
Rodriguez 44 Jerez

To do this we created a list called persons.

Every time a person is saved, the List is cleared, will each element of one of the data Surname, Age and Country List.

And it should be kept the name as a tag and the person list as the value of three elements, as indicated by the table I put up.

It turns out that the TinyWebDB does not support saving the list in list format, so we must pass the registration list to CSV (List to row) , is something like the separate elements:

tag
Name

value
Surame, Age, Country

Juan
"Perez", "22", "Cadiz"
Pedro
"Sanchez", "33", "Sevilla"
Luis
"Rodriguez", "44", "Jerez"

So yes you can save each record in the TinyWebDB.

I put Label5 and Label6 to visualize how the value data as CSV Record List and as seen.

We recover data when we do the opposite process, ie, the value data come in CSV format and registration must convert format list (List from CSV row) to insert them in persons list.

Once converted List, we get each element by its index, knowing that the first element is 1.

_________________
Design

Important:

In the ServiceURL property of TinyWebDB1, should you set the website where the information is stored, in our example:

http://appinvtinywebdb.appspot.com
_________________

Blocks

_______________________________
39B.- TinyWebBD data.

ip39B_tinywebdb_data

- Another way to store data using several different Labels.

- Later in the tutorial 8DfirebaseDB_datos see how you can perform this same application with a database where we can know when the values ​​have changed

_________________
Design

_________________
Blocks

__________________________________

 

- My e-mail:
juana1991@yahoo.com
- Who I am. - Cookies. Texts and images propierty autor:
© Juan A. Villalpando
Not copy texts neither images.
We use our own cookies and third-party cookies on our websites to maintain the session and your preferences, customize your user experience and obtain website use statistics.
Si continúa navegando consideramos que acepta su uso. OK    Más información