Android programming examples for gaming, BLE, fragments and Facebook
Here at androidcodeexamples.com we provide fresh insights into Android programming via several samples we hope you find useful. We share ideas for developing the classic empire-like strategy game, a Bluetooth low-energy app for data and efficient file transfer and a useful navigation drawer sample for generic UI development among others. Our target is to eventually provide some of these projects through the Github as well. For that to happen, we'd like you to send me a vote (which ones first) via email found at the end of this page.
The internet provides a vast amount of android programming examples. Unfortunately many of them are outdated, deprecated, full of ads, or otherwise messy and hard to understand. This is not the target here and we regret if such disinformation or poorly constructed code is shared in our examples. Thus we welcome all feedback preferably via email for now, until a working commentary section is in place.
Apache, thumbnails and shell scripts
In addition to these traditional Android examples, we also provide Apache scripts mainly for online image services. Apache server configuration and some sample scripts are shared. The services may be integrated to apps. A simple cloud image hosting strategy is presented in one of its subtopics.
The author used to host a website thumbnail API on immediatenet.com. This thumbnail API is presented in details. The www work in under construction at the moment, so stay tuned.
Linux shell scripts are powerful tools. Some shell script examples will show you how to check the validity of all 'canonical' tags of your html pages. Should there be a typo it will print it out. In like manner the scripts can perform some automated SEO checks on your behalf. Usually only imagination is the limit on what the scripts may do.
Programming a game on Android
Do you wish to develop a game on Android but have no idea how this might be done? First of all, game development is made simple and easy with this example. Perhaps the greatest blocker is the start of the programming? Nonetheless, a beginner's set for starting the development is brought to you with all graphics as well! We instruct you how transparent images may be used along with others to compose high quality graphics with ease.
The graphics don't need to be ugly. We disclose some information how ordered graphics may help you get going! This includes the use of transparent, opaque and similar layers that compose the final graphics perfectly. Simple java classes are described containing, indexing and rendering all the graphics.
We provide an extensive set of graphics for you to use for free even for commercial projects. However, we'd like you to make a reference to here, androidcodeexamples.com within your project if you utilize our graphics.
Android Bluetooth data transfer
Android Bluetooth Low Energy is booming but are you ready? Data and file transfer mechanisms aren't handled in the usual way. Brand name sportwatch manufacturers know how this happens in the most optimal way - don't stay behind! This example covers the Android side with all the details required for this data transfer to happen. BLE data transfer rate is sufficient for sending / receiving relatively small amount of data, at most some megabytes. Of course much larger chunks may be transferred but it starts to consume several minutes of time.
In the Facebook API example a way to pick the information via the Graph API is explained via Java code. This Facebook API has changed a lot during the past years making many examples seen on the Internet quite useless or at least deprecated. The ultimate target in this sample is to request the user data after logging in to Facebook - the user's first name and Facebook id. The figure on the right-hand side illustrates an Android app that has integrated the Facebook login button. When the user presses the button, the system will automatically login if the FB app or browser instance has an open connection. Otherwise it will prompt for the login credentials (passwd etc). After a successful login, the Android app is able to pick some user data such as the first name.
This particular app called SelfAd uses the first name for broadcasting it out for others to see. This happens via the Bluetooth Eddystone broadcasts. The URL to the FB picture is first shortened via the Google's URL shortener service. Next, if it's a public picture it's broadcast to everyone via BLE. More of this may be discovered in the Playstore app called SelfAd.
Google URL shortener and decoder
Google's URL shortener API is disclosed with two wonderful examples: one to shorten an URL, another to restore the original long format URL from the short. Either you have a long URL to be shortened or a short URL to be converted back to the long format - these examples will guide you how to manage that. This sample code is well tested with a vast number of Android phones from 5.0 up to the latest on the market. By the way, you need the Google API key from Google's developer console.
Navigation drawer integrated with tabs and fragments
A simple application called "SelfAd" is set as an example on working with Android tabs and fragments. There's a number of ways to go wrong so watch out! XML declarations, working source code and many insights are shared via this example. Personally I've found quite a few ways to do this improperly, sooner or later hitting a dead end. Starting all over from the beginning wasn't nice.
Purpose of this example code archive
There are numerous examples on the Internet that may mislead, suggest deprecated code or otherwise make you spend a lot of time for operations that only cause more trouble at the end. Thus, these examples should be good alternatives for these outdated examples.
About the author
The author, Eero, works as a consultant at Offcode ltd, Oulu, Finland. He has focused on Linux audio, Linux kernel and other Linux audio related projects. He has been involved in several Android projects effectively involving all the layers from the kernel up to the individual built-in apps. Android related projects have been dual-display integration, DSP algos, audio tuning, kernel audio among a number of other parts. Android apps and shell scripts have been developed as spare time activities.
Written on April 2018 by Eero Nurkkala, Offcode Ltd.