Creating our first application

App Inventor for Android is an open source web application originally provided by Google, and now maintained by the Massachusetts Institute of Technology (MIT). It allows newcomers to computer programming to create software applications for the Android operating system (OS). It uses a graphical interface, very similar to Scratch and the StarLogo TNG user interface, which allows users to drag-and-drop visual objects to create an application that can run on Android devices. In creating App Inventor, Google drew upon significant prior research in educational computing, as well as work done within Google on online development environments.

You don’t need to install any software for APP inventor to execute in your computer; you just need your Gmail account to access the APP inventor interface.

To enter APP Inventor you just need to go to: http://appinventor.mit.edu/explore/.

Go to create apps to start designing the app.

First we need to have an account with Gmail; we need to create the file like we see in the following screenshot:

Creating our first application

Go to menu Projects and Start New Project:

Creating our first application

Write the name of the project:

Creating our first application

In the following screenshot, we write the name of our project as aREST:

Creating our first application

On pressing OK, we will see the project created:

Creating our first application

Designing the interface

Now it's time to see how to create the interface of the application, after we create the project we click on the name of the project, and we will then see the following screen:

Designing the interface

In the user interface that we have on the left-hand side (you can see all the objects), to move an object to the main screen you just drag Web Viewer and Button, as shown in the following screenshot:

Designing the interface

In the previous screenshot, we can see the interface of the app that we will use to control our Arduino board.

Communicating APP Inventor with Arduino ethernet shield

Now we will see how to communicate the application with Arduino via Ethernet networking.

In the properties of the Web Viewer control, we will see the home URL:

Communicating APP Inventor with Arduino ethernet shield

In both controls we have the URL of our Arduino Ethernet shield, we will make a request using the RESTful services, and we will send the following requests from the application:

  • http://192.168.1.110/digital/7/1
  • http://192.168.1.110/digital/7/0

Code for APP Inventor

The blocks editor in the original version ran in a separate Java process, using the Open Blocks Java library for creating visual blocks programming languages and programming.

We have the code for APP inventor, when we click the buttons we call the web service, to do that you just need to do the following:

  • Go to the screen interface that says Blocks
  • Drag the When...Do block one per button
  • Inside the block that you just dragged before, put the Call...WebViewer.GoToUrl block
  • In the URL of the block, put the WebViewer.HomeUrl block

To close the application:

  • Drag the When...Button.Click Do block
  • And inside the block put the close application block
Code for APP Inventor

We will have the following results when we open a web browser:

Code for APP Inventor

The following screenshot shows the application running on a mobile phone:

Code for APP Inventor

The following image shows the final results with the connections:

Code for APP Inventor
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.152.17