android emulator+location

How do I test location services on Android running on the emulator (icecream 4.0.3 at this time)?

This works in getting the data posted:

private void setupLocationListener() {
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new MyLocationListener();

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

NOTE: Using LocationManager.NETWORK_PROVIDER seems to fail and give weird exceptions on the emulator. So magic tricks are needed as usual.

How do I post location updates from the emulator? Seems through the Dalvik Debug Monitor Server (DDMS). Why Server? No idea where that name came from.

Most instructions expect you to run Eclipse IDE with ADT plugins, including the special view for this. In other tools such as IntelliJ, you are left on your own. So go to you install dir for the Android SDK and

…\android-sdk\tools\ddms.bat is the place to start the tool.

Where do you post the location updates(assuming your debugger manages to connect to your emulator)?

On the top right corner of the DDMS window is a tabbed panel. Choose “Emulator Control”. Scroll that tab down and you find the place “Location Controls”. There you can post location updates and the code above actually receives them. Oh how wonderful, eh?

 

 

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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