Icemanind
Icemanind

Reputation: 48686

Continually sending GPS data to the Android emulator

I am writing an app for Android that will measure speed as the Android device is moving, using the GPS receiver. I know I can telnet into the Android emulator and send Geo coordinates using the "geo fix" command. What I want to know though, is there a way to continually send geo fix data to simulate a car moving down a street? Otherwise, how else can I test my application?

Upvotes: 1

Views: 1544

Answers (3)

ingsaurabh
ingsaurabh

Reputation: 15269

Hi in my first GPS based project I faced the same problem so I write a java code that will send GPS Fix to my android emulator below is the snippet

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Main {

    static final int PAUSE = 4000; // ms
    static final float START_LONGITUDE = 51, START_LATITUDE = -1.3f;
    static final int NO_SAMPLE = 100;
    static final float DELTA_LONGITUDE = 0.000005f, DELTA_LADITUDE = 0.000005f;

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 5554); // usually 5554

            PrintStream out = new PrintStream(socket.getOutputStream());
            float longitude = START_LONGITUDE, latitude = START_LATITUDE;
            String str;

            for (int i = 0; i < NO_SAMPLE; i++) {
                str = "geo fix " + latitude + " " + longitude + "\n";
                out.print(str);
                System.out.print(str);

                Thread.sleep(PAUSE);

                longitude += DELTA_LONGITUDE;
                latitude += DELTA_LADITUDE;
            }
        } catch (UnknownHostException e) {
            System.exit(-1);
        } catch (IOException e) {
            System.exit(-1);
        } catch (InterruptedException e) {
            System.exit(-1);
        }

    }
}

Upvotes: 5

Enrique
Enrique

Reputation: 10117

You can use a library like javassh to programmatically send the telnet commands to the emulator.

Upvotes: 0

Krishna
Krishna

Reputation: 1474

write the application and install the apk file in a GPS enabled android mobile. you can see the approximate speed at which the android mobile is moving from place to place.

Upvotes: 0

Related Questions