Because app's are being used almost everywhere, I decided to make my own tutorial on how
For exchanging the data between the server and the client, I'm going to
I'm assuming you already have a running Raspberry Pi with
For the Raspberry Pi you'll also need software. As
First open a web-browser and go to:
Open the database Parts.
Create new table Parts with 3 fields.
Auto increment: v
On the Raspberry Pi we'll need 4 files. You need to place them in the www directory of your raspberry
The db_config file is used for storing the username, password and database name
The db_connect file is used to connect to the database specified in the db_config file.
The db_create file is used to create a row in the table in the connected database.
The db_view file is used to get all data stored in the database.
In this step I'll explain how
Here we will make the layout of the app and in the next step I'll explain how to make the app working and how to communicate with the raspberry
So first start Android Studio.
Give your app a name and choose the directory to place it. Press Next.
Choose which devices you would like to support. I'm using phones starting from android 4.0.3.
After that you need to choose the activity. Choose: "Blank Activity".
Let the last screen as it is.
After all these steps, you get an example"hello world"app.
In activity_main.xml remove the
In values/strings.xml remove:
Go back to main_activity.xml
Drag a linear layout (vertical) to the top left corner of the screen.
Drag 2 text fields to the screen. The first one plaintext and the other one Number.
At the right scroll down
Change this for the first one to Name and for the second one to part_nr.
At the right scroll down
Change this for the first one to Name and for the second one to Part Number.
Now drag a button onto the screen and change"text"to Send.
Now is the layout done.
You can test the app by connecting your phone to your computer and compiling the app
This will take a while.
It should look something like the last image.
Up to the coding of the app.
For making an app work, you don't only need a layout. You also need the code running in the background.
The language we are going to use is Java, because all
First of all, you need to download the attached file.
This file is a library so you can easily use JSON.
Place this file in:
For me it's:
After that you can open JSONParser in android studio. You now need to change the
Open the file MainActivity.java
Place this in the main class.
Then we need a JSONparser object to send the data. So place this line under the previous line:
Now we need two EditText items, so we can extrude the inserted text. This goes under the JSONParser.
We move on to the
editText2 = (EditText) findViewById
This is the class Create_part:
@Override protected void
@Override protected String doInBackground
String String_name =
String Int_Part = editText2.getText
// Do the HTTP POST Request with the JSON parameters
// Change"RaspberryPi_IP to your home IP address or Noip service
JSONObject json =
// Open a new activity to confirm it was sent. We're going to create it later.
Now you can make a new function called Send. In this function you callCreate_Part. Like so:
In the activity_main.xml you
Ok your almost done, now you only need to make a new activity like you see in the image.
Change the activity name to: ConfirmActivity
Now go again to strings.xml and change the"hello_world"string
Now it should be done.
Rebuild the app and test it on your phone!
I'm going to make a video for this tutorial, but now I don't have time for it.
If you have questions/remarks please share them and I will see if I can answer them.
Thank you very much for following this
P.S. Please be kind, it's my first
This tutorial is originally by Laurens-Wuyts.