I’m hoping someone can help me with an issue I’m having with sending emulated GPS data to an Android AVD in Eclipse. If I run the application on a real device everything works fine, but when I attempt to uses the built in emulator in eclipse nothing will happen. I have also tried telneting into the AVD and issuing the geo fix command. Below is the code I am using although I don’t think there is anything wrong with it if it works on the real device
The manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.TestGoogleMaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:targetSdkVersion="10" android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TestingGoogleMapsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
The Main Code
package net.TestGoogleMaps;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class TestingGoogleMapsActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
public void updateWithNewLocation(Location location)
{
Context contextApp = getApplicationContext();
String text ;
int duration = 2000;
if(location == null)
{
text ="Null Location";
}
else
{
text = "Lat : " + location.getLatitude() + " Lon: " + location.getLongitude();
}
Toast toast = Toast.makeText(contextApp, text, duration);
toast.show();
}
}
I will also get the following error sometimes when simulating the GPS data from eclipse to the device in the LogCat tab of eclipse.
05-31 02:31:35.158: E/InputQueue-JNI(347): channel '406e6640 net.TestGoogleMaps/net.TestGoogleMaps.TestingGoogleMapsActivity (client)' ~ Publisher closed input channel or an error occurred. events=0x8
Any help would be greatly appreciated!
I known your problem, You can set your current (long/lag) manually at
DDMS->Devices->Emulator Control->Location Controls->Manual->input (Long/Lag) and SEND