last day (14 days later) » 

4:16 PM
3
A: Samsung and Google Location API crashing

Daniel NugentEdit: From the line in your comment where the NullPointerException is happening, just ensure that mLastLocation is not null. if (mLastLocation != null){ address = server + String.valueOf(mLastLocation.getLatitude()) + "&lng=" + String.valueOf(mLastLocation.getLongitude()) + "&distance=" + d...

 
Should I use then if(mGoogleApiClient != null && mGoogleApiClient.isConnected() && mLastLocation != null) ? It would check everything at once
 
@jeand'arme It just depends on what you are doing. You would not want to check all three at once before this line: mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); Note that getLastLocation() has a high tendency to return null, so a better approach would be to register a location listener if you get a null value. See this post: stackoverflow.com/questions/16830047/…
 
I will try using location listener because my app is fully location-dependent.
 
@jeand'arme I just updated the answer with a guide to set up a LocationListener, take a look.
 
I updated my question. Please, take a look.
Ok, I registered LocationListener in onConnected() and address that is based on mLocation is done in Callback and so far it works. If it won't crash on tests I will accept that answer since it helped me a lot :)
 
4:16 PM
@jeand'arme No problem! Is it working for you now?
 
Yes, thank You. Thank god Google Location Api has this interface with onConnected() :) Cheers, man!
Ok, those Samsung phones are really up to something: they don't want to read location... Are they so modified in system terms that they just are different to use? Should I update this question or make a new one witch applied changes (since LogCat is not providing errors)?
 
@jeand'arme It works fine for me on my Samsung S4. Do you have the latest version of Google Play Services on your Samsung devices?
@jeand'arme Also, make sure that the GoogleLocationAPI is connected before you call requestLocationUpdates() in order to register for location callbacks. You can use the onConnected() callback in order to do that. I just edited the answer, take a look at the edit at the bottom.
 
I tested it on Galaxy Note 2 emulator (provided by Genymotion) and it works great. I sent my app to my brother who got problems with it (he has Note 2) and I hope it will eventually be good now because otherwise I don't know what else could be the problem. One question: if I don't use fragments should I use "maintain state while resolving error" from this link developer.android.com/google/auth/api-client.html ? Thanks in advance, as always You deliver great help, Daniel :)
 
@jeand'arme Make sure that your brother has an updated version of Google Play Services. He should get a prompt to upgrade from the getErrorDialog() call if he needs to upgrade. Not sure about the maintain state thing, I'll check that out later when I have time.
 
Just went through everything we could on Skype. So, he has the latest Google Play Services. He still couldn't get his location - even wth GPS turned on. I'm looking for a solution how to get coarse location if fine location fails. Maybe that could be a workaround since it could happen to other users as well. I have updated question with recent code, maybe You'd like to take a look. Every method related to location is there.
I found something interesting on my brother phone now. To do thing based on location there is (mGoogleApiClient != null && mGoogleApiClient.isConnected()) if statement. Interestingly, it can't locate itself, but apparently GoogleApiClient is not null and GoogleClientApi isConnected so now it's even more confusing because he can do things that normally shouldn't work (in that case location is defaulted to lat = 0 and lon = 0). How on earth it can be connected and yet not locate itself? #confused
 
4:16 PM
@jeand'arme Sorry, just getting around to looking at this now. I just looked at your updated code, and it looks good to me. Whatever the problem is, I don't think it's your code.
 
Are there any workarounds like if location is not obtained then get location through android.location.Location ? I know this library is going to be deprecated, but could be this a reliable solution?
 
@jeand'arme can you also show where mFusedLocationCallback is defined? The onLocationChanged() callback should be defined in this object.
 
sure, it's defined before onCreate() and it's like this: private LocationCallback mFusedLocationCallback = new LocationCallback(); which is made as You described (class with LocationListener interface and empty constructor)
 
@jeand'arme Ok, just wanted to rule that out as the problem. Does it get into the onLocationChanged() callback on your brother's device?
 
That will take me 2-3 hours since he's working right now, but as soon as I will get feedback from him - I will notify here.
 
4:17 PM
Can you post your full Activity class to a gist on gist.github.com? I can run it on my Samsung S4, and see if it works!
 

last day (14 days later) »