(Android location) Gets a bit further but still not calling onLocationChanged - just renders the text for the first location retrieval and nothing else after that

This commit is contained in:
twinaphex 2013-12-21 14:58:29 +01:00
parent c68312fe31
commit be5609269a

View File

@ -1,8 +1,10 @@
package com.retroarch.browser.retroactivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.retroarch.browser.preferences.util.UserPreferences;
@ -10,7 +12,6 @@ import android.app.NativeActivity;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@ -21,9 +22,7 @@ import android.widget.Toast;
* activities.
*/
public class RetroActivityLocation extends NativeActivity
implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener, com.google.android.gms.location.LocationListener
implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener
{
/* LOCATION VARIABLES */
private static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 0;
@ -50,8 +49,18 @@ LocationListener, com.google.android.gms.location.LocationListener
// Display the connection status
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
location_service_running = true;
// If already requested, start periodic updates
mLocationClient.requestLocationUpdates(mLocationRequest, this);
if (mUpdatesRequested)
{
mLocationClient.requestLocationUpdates(mLocationRequest, this, null);
}
else
{
// Get last known location
mCurrentLocation = mLocationClient.getLastLocation();
locationChanged = true;
}
}
/*
@ -62,8 +71,7 @@ LocationListener, com.google.android.gms.location.LocationListener
public void onDisconnected()
{
// Display the connection status
Toast.makeText(this, "Disconnected. Please re-connect.",
Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
// If the client is connected
if (mLocationClient.isConnected())
@ -73,7 +81,7 @@ LocationListener, com.google.android.gms.location.LocationListener
* The current Activity is the listener, so
* the argument is "this".
*/
mLocationClient.removeLocationUpdates((com.google.android.gms.location.LocationListener) this);
mLocationClient.removeLocationUpdates(this);
}
location_service_running = false;
@ -97,17 +105,11 @@ LocationListener, com.google.android.gms.location.LocationListener
try
{
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(
this,
CONNECTION_FAILURE_RESOLUTION_REQUEST);
/*
* Thrown if Google Play services cancelled the original
* PendingIntent
*/
connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);
}
catch (IntentSender.SendIntentException e)
{
// Log the error
// Thrown if Google Play services cancelled the original PendingIntent
e.printStackTrace();
}
}
@ -129,13 +131,14 @@ LocationListener, com.google.android.gms.location.LocationListener
{
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (update_interval_in_ms == 0)
mLocationRequest.setInterval(1000 * 5);
mLocationRequest.setInterval(5 * 1000); // 5 seconds
else
mLocationRequest.setInterval(update_interval_in_ms);
// Set the fastest update interval to 1 second
mLocationRequest.setFastestInterval(1000 * 1);
mLocationRequest.setFastestInterval(1000);
}
/**
@ -149,6 +152,7 @@ LocationListener, com.google.android.gms.location.LocationListener
*/
if (mLocationClient == null)
mLocationClient = new LocationClient(this, this, this);
// Start with updates turned off
mUpdatesRequested = false;
@ -232,10 +236,13 @@ LocationListener, com.google.android.gms.location.LocationListener
*/
public boolean onLocationHasChanged()
{
boolean ret = locationChanged;
if (ret)
boolean hasChanged = locationChanged;
// Reset flag
if (hasChanged)
locationChanged = false;
return ret;
return hasChanged;
}
// Define the callback method that receives location updates
@ -254,21 +261,6 @@ LocationListener, com.google.android.gms.location.LocationListener
//Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onProviderDisabled(String provider)
{
}
@Override
public void onPause()
{