Latest Entries »

In this post I’ll show you an approach for setting up the camera  in Android devices for image processing. More exactly, access camera hardware, create a surface for the preview, handle camera and preview callbacks, get image data as frames.

First thing to do, create a new Android project in Eclipse with whatever settings you like. I would recommend a minimum target of 8(2.2). Keep the default activity.

Next, declare the following permissions in your manifest

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="" />
<uses-feature android:name=""/>

– the autofocus is optional, but recommended.

Next, let’s create the needed classes first. Create a class derived from android.view.SurfaceView and implementing android.view.SurfaceHolder.Callback. This will be the container for the camera image frames.

Create a class derived from android.view.View – this will be drawn on top of the original preview(call it something along the lines of DrawOnTop).

Briefly, this is how everything will work:

  • your main activity will instantiate two class members of type the above classes you’ve created and add it to its view
  • the preview class will handle camera creation and release, camera callback and top view instatiation. It will set camera params to highest FPS and minimum resolution on surface creation, will allocate and release camera when appropriate . In the surfaceCreated overridden method is the callback which retrieves camera frames from preview.
  • the top view class declared will be instantiated in the preview class, and in its onDraw method will handle image processing and optionally, display processed images over the original one. This will be called for every frame.

I won’t post more source code as you can get a working eclipse project from the link below.

For image processing function, I would suggest OpenCV library, an open source project which has an android port also. Very easy to pick it up, and fits well with the “camera framework” I presented you. Look for comments in the source code for the right place to insert image processing function(TopView class).

Take care with you processing functions as mobile devices are pretty limited in terms of hardware resources. It can get quickly slow, when processing real-time image frames, and you’ll lose frames.

Download Eclipse Android project – camera image process


I’m putting up the last cryptographic algorithm I implemented in Java. It’s the winner of AES contest, providing high security and good speed.

It is called Rijndael or more commonly AES. I wont bother you with details anymore. For any references wikipedia is your friend.

Here is the wikipedia article about it, and more helpful check out the external links for a complete description of the algorithm.

Apart from the others I talked about, AES uses pretty advanced mathematical operations in the Galois Field.

Sorry for the lack of comments in the source code I’m putting below, but functions names are pretty descriptive and you should be able to pick it up if you go through it having some AES description document at hand. Call me lazy…that’s the truth 🙂

I’ve also put together an Eclipse project including all algorithms I’ve discussed, with some test cases.

Download implementation file

Download Eclipse project with all algorithms

In this post, I’ll show you how to add overlays to a Google map view in Android. And making it more interesting is the way we add them. For this example lets choose a rectangular shape which can be drawn by dragging the finger on a MapView component. Although this is the simpler case, I’ll show you in a later post a circle overlay example. You could use this for defining zones on the map in a more interactive way.

First let’s build a simple app with a MapView as an activity. If you already have it skip to next section.

  • get a map api key from here . You’ll need the certificate used to sign the application and extract it’s MD5 fingerprint. You’ll basically need 2 api keys – one for emulator and one for device(if you test on it).

Continue reading

MARS is another AES candidate, operating on block of 128 bits and supporting key raging from 128 to 400 bits. Offers high security and high data rates.

Work on 32 bit words, based on a type-3 Feistel network in which one word of data is used to update the other 3 during the rounds. Uses simple operations like additions, subtraction and xor. It also uses a lookup table of 512 entries of 32 bit words called S-box. Sometimes this table is seen a two tables of 256 entries.

S-box table is given in the source code as a single table even if in code I use operations virtually dividing it. Other operations include fix rotations and data-dependent rotations, also multiplication modulo 2 raised to 32.

Continue reading

RC6 algorithm was developed by RSA laboratories from USA. It’s an improved version over its predecessors like RC2, RC4,RC5. It was proposed as an AES candidate for substituting DES algorithm. Given this, it was developed having in mind the AES specifications like operating on 128 bit blocks.

RC6 is a fully parameterized algorithm denoted like RC6 – w/r/b (w – word length, r – rounds, b – key lenght). For AES specs w = 32, r = 20 and can be refered as simply RC6.

The key length b can be anywhere between 0 and 255 bytes. Most used values are 128, 192 or 256 key length(in bits).

For all cases, RC6 work on 4 words of w bits utilizing the following basic operations.

Continue reading

In my next posts on java development I’m gonna share with you a series of encryption algorithms implemented in java(not quite fast but more clear and organized).

I’ll start with a good old one: DES algorithm.This is good for introduction, because it represent an old standard on which many new algorithms are built, and is quite easy to understand. It will naturally lead to another algorithm: Triple DES – as you’ll see later.

DES is a symmetric block cipher, operating on blocks of 64 bits of data and a key of 64 bits. Deciphering is done with the same key but in reverse order. Only 56 bits of the key are used actually in the process. Remaining 8 bits are used for parity check, therefore can be discarded.

Next is a brief description of the algorithm along with the code.

Continue reading

[Update]  The information in this post might be outdated. It worked at the moment of writing, but I don’t have the time to do a new research on the subject. I leave this post as is, it might work, or it might guide others to research the subject. Probably this feature still exists in some way.


Have you ever wondered if Android market sends you information at the moment of app install? Wouldn’t be nice to create custom links to your android application, including bits of information about the referrer, and send it directly to the app for processing at install? This could be a simple and accurate solution for mobile app install tracking but I’m sure you can find this useful in many ways…

With Android, you actually get this information as a broadcasted intent by android market at install time – even before opening your app.

Continue reading