I am getting an issue with my app on S5 devices (test on two), but it works fine on s4 and s3. I think it has something to do with Kitkat API 19 vs 18. I tested various configurations and while it would work on the S3 every single time, the S5 would not work unless location services were on and I loaded a fresh install. I have put all relevant code below:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//set up Factual
FactualRetrievalTask task=new FactualRetrievalTask();
//set up location
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
String provider=locationManager.getBestProvider(newCriteria(), true);
Location l = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
//ask for all places within the nearest x meters.
Query q=new Query()
.within(new Circle(l.getLatitude(), l.getLongitude(), 5000))
.sortAsc("$distance")
.only("name","price")
.limit(25);
task.execute(q);
The setup for Location Services
public Criteria newCriteria(){
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
c.setPowerRequirement(Criteria.POWER_LOW);
c.setAltitudeRequired(false);
c.setBearingRequired(false);
c.setSpeedRequired(false);
c.setCostAllowed(true);
return c;
}
public void updatedWithNewLocation(Location location) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location l = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
}
//Location Listener
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updatedWithNewLocation(location);
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
};
I get an error telling me there is a NullPointException at the Query (once again only on the s5 device), but I don't understand why it only happens on the API 19 phones. I would appreciate any help.