Ardroid Environment Sensor - My First Android - Arduino Project
Recently, I have spent most of my spare time on arduino, an open-source electronics prototyping platform.
Arduino is very easy to use that one with little hardware knowledge like me could start making something quickly, and with various shields and sensors, it is also very powerful.
Ok, let’s go to the main topic today, my first android arduino project.
The reason for the small project is very tricky, that is, I usually doubt the weather and envrionmental info from official departments, especially for the PM 2.5, As a result I decided to build an environment sensor and take it with me every day. The data around me is the most accurate one, right?
Above is how ardorid looks like, at the time of writing, I havn’t found a satisfying PM2.5 sensor, so you can only see two lines showing.
The basic idea is:
android device (my Huawei Y300) will act as a collector, analyser and display of the envriomental data.
arduino(openjumper mega2560, openjumper sensor shield v3, bluetooth adapter, dht11 sensor) will retrieve data and feed to the collector.
Some details of the tech stack:
For the beautiful dynamic chart, the framework is AChartEngine.
For communication between android and arduino, Firmata is your friend.
Also, bluetooth is a nice choice besides google ADK board. OpenJumper sensor shield v3 makes the integration of bluetooth module, DHT11 sensor supper easy.
- Others like the battery-powersource, gradle will lead you a good life:)
Please refer to Github for the code.
Android Toast Usages and Tests
I have been perplexed for a long time by the duration parameter of android Toast function, before I noticed the warning message from android studio
The right way is
I will demonstrate how to test toast function with Robolectric
1, For default toast message
Also, you can use
To check shown toast count
To verify a toast message has been displayed
To get all shown toasts
To reset all shown toasts list
2, For custom toasts
1 2 3
For busy developers who don’t have time to look at source codes of robolectric. :)
Implement Email Function in Android
There are several ways to implement email function in android, with their own pros and cons. I will try to summarize everything here, and you can find a demo application at the end.
1) Use installed mail apps
Create an intent with ACTION_SEND and mailto scheme:
MimeType can be set to message/rfc822 instead of text/plain, to limit applications displayed in the chooser dialog.
message/rfc822 stands for
Email; EML files, MIME files, MHT files, MHTML files; Defined in RFC 2045 and RFC 2046
There is also an enhanced version, from which you can determine what will be displayed in the chooser dialog.
1 2 3 4 5 6
2) Use the java mail api
(ported to android by Jon Simon).
Firstly, you will need to download three jar files from https://code.google.com/p/javamail-android/ .
Then, simply follow the code provided in the demo application, or you can refer to http://www.tutorialspoint.com/java/java_sending_email.htm for a comprehensive guide.
3) Use specifically built backend Api
Most applications have a backend service, it is easy to add an api that collects info from handsets and send mail on the server side.
Demo application: (last update on Aug, 4, 2013)
http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application http://stackoverflow.com/questions/6827407/how-to-customize-share-intent-in-android http://en.wikipedia.org/wiki/Internet_media_type http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android http://developer.android.com/guide/components/intents-filters.html
Add an Android Library Project in Intellij or Android Studio
It can be tricky sometimes when adding an android library project in intellij or android studio. The reasons may vary from time to time but two I recently encountered are:
- Automatic update of project.properties is disabled in intellij, thus the android library project cannot be added.
- Creating a new library module in android studio, for an ant based project, Studio only creates a settings.gradle, but forget to change the project.properties.
So far, the root cause is clear, the inconsistency between ide settings and android configs.
- You can manually update project.properties to a correct value
- Remember to update settings in your IDE
Octopress on Heroku - Day 2
- Added several plugins, including comments from disqus, my reading from douban, QR code and readability
- All these plugins and even more can be found here
- The explanation for Douban plugin is misleading, fixed and sent a pull request
- Use sub modules to manage third party plugins?
- A better place for facebook like and twitter buttons?
- Themes update
Octopress on Heroku - Day 1
- Setup octopress according to the documentation
- Update blog configuration, ruby version as well(required by heroku)
- Created a test blog
- Update google analytics
- Thanks to this article
- Markdown cheat sheet
- Google analytics not working, solution as mentioned above
- Slow connection to heroku
but only got Operation/Connecting timed out error. To fix the issue, manually add ~/.ssh/config, and put following lines in it:
1 2 3 4 5 6
Thanks to this article
This Is a Test
This is a test