anistn / android-protips-location Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/android-protips-location
Automatically exported from code.google.com/p/android-protips-location
/* * Copyright 2011 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ** QUICK START GUIDE ** 1) Make sure you've downloaded and installed the Android Compatibility Library: http://developer.android.com/sdk/compatibility-library.html 2) Obtain a Google Places API key from: http://code.google.com/apis/maps/documentation/places/#Limits And assign it to the MY_API_KEY static constant in PlacesConstants.java 3) Obtain a Backup Manager API key from: http://code.google.com/android/backup/signup.html And assign it to the backup_manager_key value in res/values/strings.xml ** About this Project ** Project Home Page: http://code.google.com/p/android-protips-location/ Maintained by: Reto Meier http://www.twitter.com/retomeier http://blog.radioactiveyak.com Uses the Google Places API to mimic the core functionality of apps that use your current location to provide a list of nearby points of interest, allow you to drill down into the details, and then checkin / rate/ review. It is an open-source reference implementation of a location-based app that incorporates several tips, tricks, best practices, and cheats for creating high quality apps. Particular attention has been paid to reducing the time between opening an app and seeing an up-to-date list of nearby venues and providing a reasonable level of offline support. The code implements all of the location best-practices for reducing latency and battery consumption as detailed in my Google I/O 2011 session, Android Protips: Advanced Topics for Expert Android Developers: http://www.google.com/events/io/2011/sessions/android-protips-advanced-topics-for-expert-android-app-developers.html
What steps will reproduce the problem?
1. start the app
2. rotate the between landscape and portrait
3. check logcat
Expected:
- no logcat messages about leaks
Actual:
- leak indicated in logcat:
E/ActivityThread( 8110): Activity
com.radioactiveyak.location_best_practices.UI.PlaceActivity has leaked
IntentReceiver
com.radioactiveyak.location_best_practices.utils.GingerbreadLastLocationFinder$1
@419b1f00 that was originally registered here. Are you missing a call to
unregisterReceiver()?
App built from source 2012-0 with Android 3.2 API, running on 4.0.4 (Samsung
Galaxy Note).
Original issue reported on code.google.com by [email protected]
on 3 Aug 2012 at 6:51
1. in PlacesUpdateService and PassiveLocationChangedReceiver, the type for
latitude/longitude values stored in SharedPreferences is long. This causes the
stored values to be clipped losing the decimals.
=> Needs conversion to float, or to be multiplied by 1E6 (microdegrees):
save in SharedPreferences with prefs.putInt(lat * 1E6)
use with loc.setLatitude(prefsLat / 1E6)
this would be more consistant with GeoPoint's getLatitudeE6() and
getLongitudeE6()
2. Compared to this (great!) tutorial, I actually implemented
SP_KEY_FOLLOW_LOCATION_CHANGES into a Preferences activity. When set to false,
it creates an
IllegalArgumentException: Receiver not registered
in disableLocationUpdates() when calling
unregisterReceiver(locProviderDisabledReceiver)
=> Needs verification or try/catch.
Thanks for this very helpful tutorial. I have also implemented many of the
issues reported here...
Original issue reported on code.google.com by [email protected]
on 5 Dec 2011 at 11:24
Hi Reto,
Thanks for your example project !
It looks like the methode Criteria.setAccuracy does accept only:
Criteria.NO_REQUIREMENT = 0
Criteria.ACCURACY_FINE = 1
Criteria.ACCURACY_COARSE = 2
But in the 'GingerbreadLastLocationFinder' class, you use:
criteria.setAccuracy(Criteria.ACCURACY_LOW);
Criteria.ACCURACY_LOW = 1, the same than Criteria.ACCURACY_FINE !!!
It should be
criteria.setAccuracy(Criteria.ACCURACY_COARSE)
Even worst, setting criteria.setAccuracy(Criteria.ACCURACY_HIGH); throw an
exception since Criteria.ACCURACY_HIGH (3) > Criteria.ACCURACY_COARSE (2)...
Maybe the Criteria constants should be set as enum or renamed, or something
else to not be misused...
Thanks,
Seb.
Original issue reported on code.google.com by [email protected]
on 28 Jun 2011 at 8:17
It looks like there are a couple of issues with the Eclair-specific code:
1) The booleans to enable/disable the services in the manifest file are
reversed:
<service android:enabled="@bool/pre_froyo"
android:name=".services.PlacesUpdateService"> and <service
android:enabled="@bool/froyo_or_later"
android:name=".services.EclairPlacesUpdateService">
should be
<service android:enabled="@bool/froyo_or_later"
android:name=".services.PlacesUpdateService"> and <service
android:enabled="@bool/pre_froyo"
android:name=".services.EclairPlacesUpdateService">
2) Several classes do
PlacesConstants.SUPPORTS_ECLAIR ? EclairPlacesUpdateService.class :
PlacesUpdateService.class
but should do
PlacesConstants.SUPPORTS_FROYO ? PlacesUpdateService.class :
EclairPlacesUpdateService.class
3) LegacyPlacesUpdateRequester is never instantiated in
PlatformSpecificImplementationFactory.getLocationUpdateRequester()
Original issue reported on code.google.com by [email protected]
on 5 Oct 2011 at 11:23
I found that both Passive and Active updates were being done when the app was
in the foreground. I had changed the accuracy to COARSE
My solution was to disable the updates for the passive listener in onCreate()
and only enable in onPause() when not exiting the app:
in onCreate
Intent passiveIntent = new Intent(this, PassiveLocationChangedReceiver.class);
locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT);
locationManager.removeUpdates(locationListenerPassivePendingIntent);
in disableLocationUpdates
if (AppConstants.DISABLE_PASSIVE_LOCATION_WHEN_USER_EXIT && isFinishing())
locationManager.removeUpdates(locationListenerPassivePendingIntent);
else
locationUpdateRequester.requestPassiveLocationUpdates(AppConstants.PASSIVE_MAX_TIME, AppConstants.PASSIVE_MAX_DISTANCE, locationListenerPassivePendingIntent);
Great article and excellent code. Thanks for this!
Original issue reported on code.google.com by [email protected]
on 13 Jul 2011 at 4:07
Hi,
great stuff an I'm using it in my current project. I found that under some
conditions (getLastBestLocation has asked for an update and has registered a
broadcast reciever but not received an update before I call cancel()) this one
can appear:
07-12 13:54:00.388: ERROR/ActivityThread(496): Service
com.eventorama.mobi.lib.service.GetLocationService has leaked IntentReceiver
com.eventorama.mobi.lib.location.GingerBreadLocationFinder$1@405f5d40 that was
originally registered here. Are you missing a call to unregisterReceiver()?
I changed the cancel() method for example of the GingerBreadLocationFinder to:
public void cancel() {
locationManager.removeUpdates(singleUpatePI);
context.unregisterReceiver(singleUpdateReceiver);
}
which fixes the issue.
Keep the good examples going it's really a valuable resource!
Original issue reported on code.google.com by [email protected]
on 12 Jul 2011 at 12:32
// If the best result is beyond the allowed time limit, or the accuracy of the
// best result is wider than the acceptable maximum distance, request a single update.
// This check simply implements the same conditions we set when requesting regular
// location updates every [minTime] and [minDistance].
if (locationListener != null && (bestTime < minTime || bestAccuracy > minDistance)) {
IntentFilter locIntentFilter = new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION);
context.registerReceiver(singleUpdateReceiver, locIntentFilter);
locationManager.requestSingleUpdate(criteria, singleUpatePI);
}
90% requestSingleUpdate ,when system get location will will send intent to
BroadcastReceiver singleUpdateReceiver
Sometime I see requestSingleUpdate not work.It make my application can not get
location.But I test GooglePlace ,it can get location
What version of the product I'm using 4.1
I 'm not understand why GooglePlace can get very good location
Original issue reported on code.google.com by [email protected]
on 5 Dec 2012 at 4:41
Shouldn't the intent filter be for "android.intent.action.BATTERY_LOW" instead
of "android.intent.action.ACTION_BATTERY_LOW"?
Intent.ACTION_BATTERY_LOW is the constant, but its value is
android.intent.action.BATTERY_LOW.
"android.intent.action.ACTION_BATTERY_LOW" does not react to any intents on my
phone, while "android.intent.action.BATTERY_LOW" does.
Original issue reported on code.google.com by icyerasor
on 29 Jun 2011 at 10:22
1. The subtle differences in (the upper half of) getLastBestLocation() between
GingerbreadLastLocationFinder and LegacyLastLocationFinder doesn't make sense
to me. The code in GingerbreadLastLocationFinder looks correct.
2. The constructor GingerbreadLastLocationFinder() sets accuracy to
ACCURACY_LOW but the comment above is about ACCURACY_COARSE (which is used in
LegacyLastLocationFinder).
I suggest one of the following refactorings:
- Rename ILastLocationFinder to LastLocationFinder and turn it into an abstract
class with common code, or
- Remove ILastLocationFinder, rename LegacyLastLocationFinder to
LastLocationFinder, put the common code there and make
GingerbreadLastLocationFinder extend that class.
While you're at it, you may also remove the redundant parenthesis in:
if ((time > minTime && accuracy < bestAccuracy)) {
Oh, and thanks for an awesome deep dive! Helped me a lot.
Original issue reported on code.google.com by [email protected]
on 26 Jun 2011 at 9:44
Hello.
I am a new in android development.
Thank you for the article
http://android-developers.blogspot.de/2011/06/deep-dive-into-location.html
I am not understand how to use PassiveLocationChangedReceiver.
I think that shoul be something like
PassiveLocationChangedReceiver lr = new PassiveLocationChangedReceiver();
IntentFilter ifilter = new IntentFilter(Intent. -=Some Intent Action=- );
var location = RegisterReceiver(lr, ifilter);
What Intent Action need to be used.
I am a Mono Android (Xamarin) developer.
Thank you.
Original issue reported on code.google.com by [email protected]
on 15 Aug 2013 at 12:53
PendingIntent locationListenerPassivePendingIntent =
PendingIntent.getActivity(context, 0, passiveIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
should instead read
PendingIntent locationListenerPassivePendingIntent =
PendingIntent.getBroadcast(context, 0, passiveIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
as you will discover if you copy this part of the code - the
PassiveLocationChangedReceiver's onReceive is never called :-)
Original issue reported on code.google.com by [email protected]
on 16 Apr 2012 at 4:20
The FroyoLocationUpdateRequester does not contain an implementation for the
requestLocationUpdates() method defined in the abstract base class
LocationUpdateRequester.
Suggested fix: pull the implementation for requestLocationUpdates() up from
the child class "GingerbreadLocationUpdateRequester".
Additional suggestion: Add a "removeUpdates(PendingIntent p)" to the class
hierarchy, so that the requester (code that actually holds the PendingIntent)
can signal to the location manager that it's no longer interested in location
updates. See attached files for implementation. Implement similar for
LegacyLocationUpdateRequester.
Original issue reported on code.google.com by [email protected]
on 28 Oct 2011 at 6:44
Attachments:
In the LegacyLastLocationFinder.getLastBestLocation() method, the tests on the
fix time are inverted!
if ((time < minTime && accuracy < bestAccuracy))
should be:
if ((time > minTime && accuracy < bestAccuracy))
if (time > minTime && bestAccuracy == Float.MAX_VALUE && time < bestTime)
should be:
if (time < minTime && bestAccuracy == Float.MAX_VALUE && time > bestTime)
and
if (locationListener != null && (bestTime > minTime || bestAccuracy >
minDistance))
should be:
if (locationListener != null && (bestTime < minTime || bestAccuracy >
minDistance))
It is less important but the comment for the minTime is misleading.
I also think the test to get the latest fix no matter its accuracy in both
LegacyLastLocationFinder and GingerbreadLastLocationFinder should not include a
check on minTime. Then,
if (time < minTime && bestAccuracy == Float.MAX_VALUE && time > bestTime)
should actually be:
if (bestAccuracy == Float.MAX_VALUE && time > bestTime)
Original issue reported on code.google.com by [email protected]
on 16 Aug 2011 at 5:17
FroyoSharedPreferenceSaver and GingerbreadSharedPreferenceSaver take in a
"backup" parameter but ignore its value, backing up preferences no matter what
happens.
Expected behavior: avoid backing up preferences if backup == false.
Original issue reported on code.google.com by [email protected]
on 13 May 2012 at 5:01
What steps will reproduce the problem?
1. hello everyone can u plz help my problem..actually there is no error in the
project ...but at run-time it says the application has stopped
unexpectedly..Please try again
2. if i upload the same project from my friend laptop to my android device i l
get the main screen which contain 1 button i.e checkin to..
but nothing happens and main screen remains as it is.
3. plz any1 help me out.
What version of the product are you using? On what operating system?
Google api 3.0...windows 7
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 5 Jun 2012 at 10:52
Hi,
I am trying to use this code under Froyo but not able to do so, is there any
specific requirement ? Can it only run on GB or Honeycomb ?
Regards
Girish
Original issue reported on code.google.com by [email protected]
on 9 Sep 2011 at 5:02
// If there are still queued checkins then set a non-waking alarm to retry them.
Alarm time set in System.currentTimeMillis() instead of
SystemClock.elapsedRealtime()
Original issue reported on code.google.com by [email protected]
on 21 May 2013 at 1:54
When I run the application under LG Optimus One in portrait mode, the "checkin"
button does not show up (it is somewhere off-screen on the right). If I rotate
the phone to landscape mode it shows up fine.
Normally this wouldn't be a big deal, but the first time I ran this application
I thought it wasn't working. All I saw was a black screen asking me to check in
but no obvious way to do so. It took me a couple of minutes to figure out that
I had to rotate the phone.
Please move the checkin button under portrait mode so it fits in the screen.
Alternatively (cheap hack) add some text asking the user to rotate the screen.
Original issue reported on code.google.com by [email protected]
on 6 May 2012 at 4:04
I found the implemention in these two files is different, but I can't
understand why.
I think the LegacyLastLocationFinder's implemention is not correct, But the
GingerbreadLastLocationFinder's implemention is correct.
Thanks for your sharing of this project, It helps me a lot
Original issue reported on code.google.com by [email protected]
on 6 Sep 2011 at 8:40
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.