11package io .nlopez .smartlocation .location .providers ;
22
33import android .content .Context ;
4+ import android .content .Intent ;
45import android .location .Location ;
56import android .os .Bundle ;
7+ import android .support .annotation .NonNull ;
8+ import android .support .v4 .app .Fragment ;
69
710import com .google .android .gms .common .ConnectionResult ;
11+ import com .google .android .gms .common .GoogleApiAvailability ;
812import com .google .android .gms .common .GooglePlayServicesUtil ;
913
1014import io .nlopez .smartlocation .OnLocationUpdatedListener ;
@@ -28,13 +32,43 @@ public class LocationGooglePlayServicesWithFallbackProvider implements LocationP
2832 private LocationProvider provider ;
2933
3034 public LocationGooglePlayServicesWithFallbackProvider (Context context ) {
31- if (GooglePlayServicesUtil .isGooglePlayServicesAvailable (context ) == ConnectionResult .SUCCESS ) {
35+ if (GoogleApiAvailability . getInstance () .isGooglePlayServicesAvailable (context ) == ConnectionResult .SUCCESS ) {
3236 provider = new LocationGooglePlayServicesProvider (this );
3337 } else {
3438 provider = new LocationManagerProvider ();
3539 }
3640 }
3741
42+ public LocationGooglePlayServicesWithFallbackProvider (@ NonNull Fragment fragment , Context context ) {
43+ if (GoogleApiAvailability .getInstance ().isGooglePlayServicesAvailable (context ) == ConnectionResult .SUCCESS ) {
44+ provider = new LocationGooglePlayServicesProvider (fragment , this );
45+ } else {
46+ provider = new LocationManagerProvider ();
47+ }
48+ }
49+
50+ public LocationGooglePlayServicesWithFallbackProvider (Context context , boolean checkLocationSettings , boolean alwaysShow ) {
51+ if (GoogleApiAvailability .getInstance ().isGooglePlayServicesAvailable (context ) == ConnectionResult .SUCCESS ) {
52+ LocationGooglePlayServicesProvider locationGooglePlayServicesProvider = new LocationGooglePlayServicesProvider (this );
53+ locationGooglePlayServicesProvider .setCheckLocationSettings (checkLocationSettings );
54+ locationGooglePlayServicesProvider .setLocationSettingsAlwaysShow (alwaysShow );
55+ provider = locationGooglePlayServicesProvider ;
56+ } else {
57+ provider = new LocationManagerProvider ();
58+ }
59+ }
60+
61+ public LocationGooglePlayServicesWithFallbackProvider (@ NonNull Fragment fragment , Context context , boolean checkLocationSettings , boolean alwaysShow ) {
62+ if (GoogleApiAvailability .getInstance ().isGooglePlayServicesAvailable (context ) == ConnectionResult .SUCCESS ) {
63+ LocationGooglePlayServicesProvider locationGooglePlayServicesProvider = new LocationGooglePlayServicesProvider (fragment , this );
64+ locationGooglePlayServicesProvider .setCheckLocationSettings (checkLocationSettings );
65+ locationGooglePlayServicesProvider .setLocationSettingsAlwaysShow (alwaysShow );
66+ provider = locationGooglePlayServicesProvider ;
67+ } else {
68+ provider = new LocationManagerProvider ();
69+ }
70+ }
71+
3872 @ Override
3973 public void init (Context context , Logger logger ) {
4074 this .logger = logger ;
@@ -80,6 +114,12 @@ public void onConnectionFailed(ConnectionResult connectionResult) {
80114 fallbackToLocationManager ();
81115 }
82116
117+ public void onActivityResult (int requestCode , int resultCode , Intent data ) {
118+ if (provider instanceof LocationGooglePlayServicesProvider ) {
119+ ((LocationGooglePlayServicesProvider ) provider ).onActivityResult (requestCode , resultCode , data );
120+ }
121+ }
122+
83123 private void fallbackToLocationManager () {
84124 logger .d ("FusedLocationProvider not working, falling back and using LocationManager" );
85125 provider = new LocationManagerProvider ();
0 commit comments