Closed no-cat-no closed 7 years ago
Tell me, how can I turn off location determination through Google Play Services and leave only GPS and WiFi?
Assuming you are using default configuration, so:
Configurations.java
public static LocationConfiguration defaultConfiguration(@NonNull String rationalMessage, @NonNull String gpsMessage) {
return new LocationConfiguration.Builder()
.askForPermission(new PermissionConfiguration.Builder().rationaleMessage(rationalMessage).build())
.useGooglePlayServices(new GooglePlayServicesConfiguration.Builder().build())
.useDefaultProviders(new DefaultProviderConfiguration.Builder().gpsMessage(gpsMessage).build())
.build();
}
Just delete this line:
.useGooglePlayServices(new GooglePlayServicesConfiguration.Builder().build())
and you're ready to go.
P.S. Do you planing to add a definition through the GSM of the towers?
DefaultLocationProvider.java
void getLocationByNetwork() {
if (isNetworkProviderEnabled() && getSourceProvider().isNetworkAvailable(getContext())) {
LogUtils.logI("Network is enabled, getting location...");
askForLocation(LocationManager.NETWORK_PROVIDER);
} else {
LogUtils.logI("Network is not enabled, calling fail...");
onLocationFailed(FailType.NETWORK_NOT_AVAILABLE);
}
}
If you change the conditions and keep only isNetworkProviderEnabled()
, network provider will be used whether there is an available active data network or not. In a scenario when none of data networks (mobile, Wi-Fi, etc. ) is available, Android Location framework provides you with location information based on Cell Towers. The precision depends on the quality and features of the cell tower.
Wow! Thanks!!!
And small question:
If you do not use Google Services, the battery will be installed faster. For tracking this is critical. Could you give advice on how to reduce battery consumption? Maybe I must use services instead of activity or something like that?
I noticed that you are not using PASSIVE_PROVIDER.
The Google Location Services API provides, in most cases, better battery performance.
Could you give advice on how to reduce battery consumption?
https://developer.android.com/guide/topics/location/strategies.html#Adjusting
I noticed that you are not using PASSIVE_PROVIDER.
https://developer.android.com/reference/android/location/LocationManager.html#PASSIVE_PROVIDER
ok, thanks.
wow @kobasek thanks for answering :) Appreciated!
Actually removing network availability check is good idea, eventually we have timeout anyway. I'll implement it that way, hopefully soon :)
And @no-cat-no if you need to customize the behaviour even further, you can create your own LocationProvider implementation and set it to LocationManager. Then, it will not use default ones, and since you're not using GooglePlayServices api provider anyway, that would mean for your case, only DefaultLocationProvider changes.
In that way, you can do any optimisation that you need to do, such as: using PassiveProvider.
I've done some minor/major "fixes" to your project @yayaa If i have more time, i'll create a PR and share all of it with you.
Nice @kobasek thanks👍 Just a few notes:
Sure @yayaa ;) Have you considered wrapping your library with RxJava?
I did, but because there are already some with RxJava i decided not to, but sure why not. I would do in a different module though, just not force people to depend RxJava if they are not already using. But please send me email if you are interested, let's not talk over a closed issue :) @kobasek
I'm making an app for China. But in China, Google Play Services do not work (Great Firewall). Tell me, how can I turn off location determination through Google Play Services and leave only GPS and WiFi?
Thanks!
P.S. Do you planing to add a definition through the GSM of the towers?