Wednesday, September 21, 2011

Use Mock GPS Location for Android Development - Part One

Recently, I am working on an Android google map app that requires some fake GPS position input. Here are several easy ways for you to quickly input mock GPS locations for your Android development:

Using Emulator:
1. Using geo fix 
cd to your .\android-sdk\tools\ folder, and then telnet to your avd. e.g.
$ telnet localhost 5554
$ geo fix -118 35
$ exit
The help geo fix shows that it takes these parameters 'geo fix log lat '...

2. Using DDMS
In your emulator control view, using the Location Controls to send the location, e.g.

Using Android Device:

Use mock location generation tool like Location Spooler: https://market.android.com/details?id=org.ajeje.fakelocation&feature=related_apps

1) Start location spooling


2) Start the app


Note:
1. Remember to save in the android manifest xml the mock location permission;
2. Enable the mock GPS location access on your droid phone. 

Also refer to here:
http://stackoverflow.com/questions/2531317/android-mock-location-on-device


Wednesday, September 14, 2011

A very simple gcc makfile for Creating and Linking a static C lib on Windows

The short makfile script below is to create and use a static c lib in gcc compiler for C code.


Requirement:
1. gcc compiler (e.g. cygwin);
2. Put in a folder the following files:
   main.c //main program, to call mylib.lib
   mylib.c //lib's src, to generate mylib.lib
   mylib.h //lib's hearder
   makefile


makefile:
#my library
LIB_SRC = mylib.c
LIB_DEP = $(LIB_SRC:.c=.h)
LIB_OBJ = $(LIB_SRC:.c=.o)
LIB = $(LIB_SRC:.c=.lib)
#main program
SRC = main.c
BIN = main.exe
# include directories
INCLUDES = -I.
# compiler
CC = gcc
# dependency
$(BIN): $(LIB) $(SRC)
$(CC) -o $(BIN) $(SRC) $(LIB)
$(LIB): $(LIB_OBJ)
ar rcs $(LIB) $(LIB_OBJ)
$(LIB_OBJ): $(LIB_SRC) $(LIB_DEP)
$(CC) -c -o $@ $< $(INCLUDES)
clean:
rm -f $(LIB_OBJ) $(LIB) $(BIN)


Add tab before for each command line.


Usage:
To run on a UNIX-like command line tool in Windows:
$ make
or
$ make main.exe
will compile and generate both mylib.lib and main.exe
$ make mylib.lib
will compile and generate only mylib.lib


For more info: GNU `make`