- 0. Introduction
- 1. Project Schema
- 2. Setup the IDE
- 3. Setup an Android Application Project
- 4. Carriots Project and Device Registration
- 5. Constructing the Android Code
- 6. Checking Data is collected in Carriots
- 7. From here on: Enhancing the project
This easy tutorial describes how to make an Android application with Android Code to send streams to Carriots. In this project you will learn how to:
- Set up your development environment
- Make an easy Android application
- Send streams to Carriots with your Android application
- Your favorite IDE, in our case Eclipse
- Android SDK
- ADT Plugin
- An Android phone or emulator
Music to listen: Radiohead - Weird Fishes / Arpeggi
This project is a quick way to create an Android application and understand how to send streams to Carriots using Android Code.
Here is the overall diagram of the project:
All the data streams sent by the phone are collected and stored in Carriots. Carriots is a huge database that collects all the information that your sensors send.
In addition to storing data, the true power of Carriots is to let you build Apps very quickly with few lines of Groovy code.
With Carriots you can build very complex Apps to support all the logic of your product on the cloud and integrate it with other devices and IT systems. But for now let’s keep it simple.
If you are a new Android developer, the best way to start is download the ADT Bundle.
ADT Bundle includes everything you need to begin developing apps:
- Eclipse + ADT plugin
- Android SDK Tools
- Android Platform-tools
- The latest Android platform
- The latest Android system image for the emulator
Setting Up the ADT Bundle
- Download ADT Bundle
- Unpack the ZIP file and save it to an appropiate location
- Open the adt-bundle-your_platform/eclipse/ directory and launch eclipse
- That's all!. Your IDE is already loaded with the Android Developer Tools plugin and the SDK ready to run
This point describes how to set up your development environment for an Android Application Project
- Select menu item -> New project -> Android Application Project
- New Project
Complete the remaining windows with the desired values for your project.
Configure the file AndroidManifest.xml
- Type the following permission before the uses-sdk tag
Add the xml Strings and layout code to create the layout
- Click on the project -> res -> values -> strings.xml
- strings.xml Location
- Add the the following code into your strings.xml file between the two resource tags
- Click on the project -> res -> layout -> your xml file
- XML Layout Location
- Add the the following code into your xml layout file
If youre registered in Carriots, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
But if you want, you can create a new device and use it in this example.
Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.
It's time to build the HTTP request that will send a stream to Carriots
- Go to src -> com.example.yourPackage -> yourMain.java and make the following changes:
- Add all the imports you will need above the Main class
- After the onCreate method, add a new class that extends AsyncTask. This class is a helper that will allow you to perform the http request in the background and after, use the information on the User Interface thread.
- Add the sendStream method after the onCreate method. It will act as an on click listener for the send button and it will instantiate a MyAsyncTask thread.
- Your Android code should look something like this
- Run on a simulator or on a device (whichever you prefer), and push the button to send a stream to Carriots
- Android App
If you get here, your device must be sending streams when you push the button.
It's time to test our control panel and check if we have new streams.
Go to “Data management” → “Data streams” and you will see your data.
- menu option
Now you know how to create a simple App for your Android phone and send streams to Carriots. But you can enhance this project in many ways.
In a second part of this tutorial, you will learn how to send GPS coordinates to Carriots.