Posts Tagged ‘Android Development’

Android: Loading files from the Assets and Raw folders

Click here to read Android: Loading files from the Assets and Raw folders

This tutorial will explain how to load files from the res/raw and the Assets folder using a String to specify the file name. Yes, there are a lot of tutorials on this subject, but they all use the automatically generated integer IDs from the R class as inputs and not many of them even mention the possibility of loading files from the Assets folder. As a result of depending on the ID, the file reference must be known beforehand.

Instead, the code featured in this post will explain how to find the reference to the file and then load it at runtime based solely on its name. This means that the reference ID and the file don’t even have to exist in the first place, and can be acquired at run time.

(more…)

Import STL libraries to the Android NDK code

Click here to read Import STL libraries to the Android NDK code

This is a quick tip for those who are beginning to write native Android code. As one may have noticed, it isn’t possible to use containers like, string, vector, list inside the NDK samples. These are all part of the STL (Standard Template Library), and are expected to be available when writing C++ code.

To add STL to your NDK code, locate the Application.mk file inside your project’s jni folder. If it isn’t there, create it. Please note that the Application.mk is not the Android.mk file! The Android.mk file instructs the compiler and the JNI on how NDK code should be handled. The Application.mk, works similarly as the Android manifest file for your NDK code, allowing the programmer to add permissions and define other applications’ properties, like such as ‘enabling’ the STL support.

(more…)

Android: Loading and playing videos from different sources

Click here to read Android: Loading and playing videos from different sources

This is the 41st post on the website! It explains how to load images from a variety of locations, such as the ‘Resources’ folder, the SD card and from a remote server. As usual, the source code is available for download at the end of the post.

Let’s start with the basics: video formats. At the time this is being written, Android supports .3gp and .mp4 video files encoded as H.263,H.264 and MPEG-4 SP file formats. For an updated list, visit this link.

(more…)

Android: loading images from a remote sever, SD card and from the Resources folder

Click here to read Android: loading images from a remote sever, SD card and from the Resources folder

As stated on the title, this post will explain how to load a image from 3 different sources: the SD card, from a remote server and from the Resources folder. Since the methods and code used to load these images from these sources are different from one another, this post is going to be divided into three different parts, one for each location.

Select one of the following links to go to a specific part of the post: (more…)

Android: touchscreen ‘swipe’ movement detection

Click here to read Android: touchscreen ‘swipe’ movement detection

This post explains how to code a simple swipe screen movement detection that can be used to control characters and other objects on an Android game or any other application.

All this code is written inside the View class, so open it up and let’s get to it. The first thing we will have to do is to create four different variables: one pair will store where the screen was touched, and the other one will be used to store the difference between the location where the screen has been pressed and where the screen has been released. Create this variables and assign zero to all of then, like this: (more…)