1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
|
import java.util.List; |
|
3 |
|
|
4 |
import android.content.Context; |
import android.content.Context; |
5 |
|
import android.content.SharedPreferences; |
6 |
import android.location.GpsSatellite; |
import android.location.GpsSatellite; |
7 |
import android.location.GpsStatus; |
import android.location.GpsStatus; |
8 |
import android.location.Location; |
import android.location.Location; |
9 |
import android.location.LocationListener; |
import android.location.LocationListener; |
10 |
import android.location.LocationManager; |
import android.location.LocationManager; |
11 |
import android.os.Bundle; |
import android.os.Bundle; |
12 |
|
import android.preference.PreferenceManager; |
13 |
import android.util.Log; |
import android.util.Log; |
14 |
|
|
15 |
|
|
77 |
satCount = 0; |
satCount = 0; |
78 |
|
|
79 |
startTime = android.os.SystemClock.elapsedRealtime(); |
startTime = android.os.SystemClock.elapsedRealtime(); |
|
|
|
|
List<String> providers = locManager.getProviders(true); |
|
80 |
|
|
81 |
boolean hasProvider = false; |
boolean hasProvider = false; |
82 |
|
|
83 |
for(String provider : providers) { |
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(cntx); |
84 |
if (provider.equals( LocationManager.PASSIVE_PROVIDER)) { |
String networkPref = prefs.getString("location", "GPS"); //default value is gps |
85 |
continue; |
|
86 |
} |
if (networkPref.equals("GPS")) { |
87 |
|
if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
|
Log.i("Provider", ""+provider); |
|
|
hasProvider = true; |
|
|
if (provider.equalsIgnoreCase("gps")) { |
|
88 |
locManager.addGpsStatusListener(this); |
locManager.addGpsStatusListener(this); |
89 |
hasGps = true; |
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); |
90 |
|
|
91 |
|
hasGps = true; |
92 |
|
hasProvider = true; |
93 |
} |
} |
|
|
|
|
locManager.requestLocationUpdates(provider, 0, 0, this); |
|
94 |
} |
} |
95 |
|
|
96 |
|
if (locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { |
97 |
|
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); |
98 |
|
hasProvider = true; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
if (hasProvider == false) { |
if (hasProvider == false) { |
103 |
// message that no suitable provider was found |
// message that no suitable provider was found |