I have a client-server application where the client sends a "ping" and the server responds back with a "pong". On receipt of the "pong", the client sends its location updates (GPS data) to the server. On receiving the location updates, the server sends a "pong" and this goes on for a while. The sockets (for sending and receiving messages) are created by the client and server in separate threads. I register the LocationListener in the main thread. The problem is that, I do not get any updates from the GPS. I checked the GPS by running a separate app that displays the number of satellites seen and the time taken for the first fix. It took about 90 seconds for the first fix.
The problem I have is very similar to the ones mentioned here and here. Also here.
My code is given below:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.getBestProvider(criteria, true);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!isGPSEnabled) {
Log.i(TAG,"PING: GPS not enabled");
} else {
Log.i(TAG,"PING: GPS enabled");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
Log.i(TAG,"PING: adding GPS status listener");
locationManager.addGpsStatusListener(PingActivity.this);
}
/*The server and client threads are started after this.*/
The LocationListener is as follows:
LocationListener locListener = new LocationListener()
{
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "PING: onLocationChanged");
Log.i(TAG, "PING: location is " + location.getLatitude() + ", " + location.getLongitude());
}
As you can see, there are just two log statements in the LocationListener and these two log statements are not printed at all. Is it because I have a thread constantly listening for updates and the LocationListener is never invoked? I also tried creating a separate activity for the GPS and registering that before starting the client-server threads.
These are the permissions in the manifest file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
The message I get in LogCat is
duplicate add listener for uid
Can someone throw some light on this? Thanks.