Android Programming

Have you ever wondered how all those Android apps are produced? Would you like to be able to create one of your very own? If so, you need Android Studio, an integrated development environment (IDE) for Android programming, from Google.

This post is all Jeff’s fault! My buddy at the computer club developed an app that launches the club’s Internet home page simply by touching the associated icon. He used a web site that allowed him to “fill in the blanks” and create an Android Application Package (.apk file) that can be installed on a smartphone or tablet.

This started me thinking about what sort of app I could use and how I would go about creating it. Initially, I thought it might be useful to have a simple app that would display the contents of the SDcard on my ‘phone. Of course, I can do this in a couple of clicks using an existing file manager (right now ES File Explorer is my app of choice), and there may well be a specific app on the Play Store that would suit my requirement, but then there is the challenge of Android programming!

A couple of YouTube videos and Android tutorials later, I discovered that I should install Android Studio. I chose the Linux version and, as a test, opted to follow the instructions in an excellent video produced by Gary Sims at Android Authority (Writing your first Android app – everything you need to know) to create “my” first app.

There are a couple of wrinkles in the process. Firstly, the video suggests that you need to install the Java Development Kit (JDK) from Oracle before installing Android Studio (currently Version 2.2). However, the release notes for Studio indicate that: “…a single download includes everything you need to begin developing Android apps”. The latter certainly seems to be the case as I was able to develop my app without specifically installing the JDK.

Secondly, the Android Authority video was clearly produced using an earlier version of Studio. While the basic content is still useful, there are a number of differences in how some of the steps are applied due to a change in the user interface of the IDE. A second video (Android Studio Tutorial For Beginners – How To Build an Android App), by Mark Price, also uses an earlier version of Studio; however, the interface is very similar to that in the current release. So, by combining aspects of both videos, I was able to successfully create the test app. Note also that this second video also has more current details of the installation process for Studio, although the process is more-or-less automatic and very simple.

Once Android Studio has been installed and the initial setup process completed, I would recommend establishing a desktop launcher to easily run the program. On the Welcome Screen, click on the “Configure” link and then select “Create desktop entry”. This will create a “Programming” option in the main menu with an entry for “Android Studio”. Right-click on the latter option and select “Add to desktop”.

The final issue that I had was testing my app in the emulator. Clicking on the menu icon for the Android Virtual Device (AVD) Manager, did not display a default smartphone in the “Your Virtual Devices Menu”. I clicked on the button to “Create Virtual Device, selected “Nexus 5” as the test ‘phone, downloaded and selected “Lollipop x86 Android 5.1” as the OS, and changed the “Emulated Performance – Graphics” option to “Hardware – GLES 2.0”. Finally, I hit “Finish”, but nothing happened; there was still no listing for a virtual device. Then, I noticed an error message in the Event Log:

NoSuchFileException: /home/toaster/.android/avd/Nexus_5_API_22.ini

On checking, I found that there was no avd folder inside .android. So, I created one and tried once again to create the Nexus 5 virtual device. This time, the error message read:

AccessDeniedException: /home/toaster/.android/avd/Nexus_5_API_22.ini

Clearly, Android Studio was trying to write a file(s) to the .android/avd folder but there was some form of problem with permissions. Checking the permissions on .android (show hidden files, right-click on the .android folder, select Properties, and navigate to the Permissions tab) showed the Owner to be root. For some reason, when installing, Android Studio had created this folder with root access only but then, subsequently, was unable to create an avd folder and write out the virtual device files. My fix was to run “sudo caja”, giving myself root access, and change the owner of the .android folder to my username (toaster). With this change in place, the Nexus 5 virtual device could be successfully created and my app tested in the IDE’s emulator.


Finally, I was also able to create a .apk file (Build – Generate Signed APK), transfer it to my ‘phone, and install the app. So, now I have a little green man icon that displays a button which, when touched, says “Ouch!” Not terribly useful, but it did bring a smile to my face!

But, am I now ready to build my “real” app to display the contents of my SDcard? Well, perhaps not. A little research suggests that this is actually a rather complex process and requires a considerable amount of Java code. There are lots of examples on the web about how to implement such an app. Perhaps I will follow up when I have more time. But, for now, the requirement for a couple of clicks in my file manager doesn’t sound too onerous!


ES File Explorer File Manager

Writing your first Android app – everything you need to know

Android Studio Tutorial For Beginners – How To Build an Android App

Creating a simple file chooser

Simple Android File Chooser

aFileChooser – Android File Chooser

This entry was posted in Android and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s