9
9
import android .Manifest ;
10
10
import android .content .Context ;
11
11
import android .content .pm .PackageManager ;
12
+ import android .location .GnssStatus ;
12
13
import android .location .Location ;
13
14
import android .location .LocationListener ;
14
15
import android .location .LocationManager ;
@@ -114,15 +115,42 @@ public void requestLocationUpdates(boolean request) {
114
115
if (request ) {
115
116
if (ContextCompat .checkSelfPermission (activity , Manifest .permission .ACCESS_FINE_LOCATION ) == PackageManager .PERMISSION_GRANTED ) {
116
117
lmgr .requestLocationUpdates (LocationManager .GPS_PROVIDER , 0 , 0 , this );
118
+ lmgr .registerGnssStatusCallback (mStatusCallback );
117
119
} else {
118
120
ActivityCompat .requestPermissions (activity , new String []{Manifest .permission .ACCESS_FINE_LOCATION },
119
121
REQUEST_CODE_GPS_PERMISSIONS );
120
122
}
121
123
} else {
122
124
lmgr .removeUpdates (this );
125
+ lmgr .unregisterGnssStatusCallback (mStatusCallback );
123
126
}
124
127
}
125
128
129
+ private GnssStatus .Callback mStatusCallback = new GnssStatus .Callback () {
130
+ @ Override
131
+ public void onSatelliteStatusChanged (GnssStatus status ) {
132
+ satCount = status .getSatelliteCount ();
133
+ fixCount = 0 ;
134
+
135
+ for (int i = 0 ; i < satCount ; i ++) {
136
+ if (status .usedInFix (i )) {
137
+ fixCount ++;
138
+ }
139
+ }
140
+
141
+ if (fixCount == 0 ) {
142
+ TextView tvAccuracy = findViewById (R .id .gpsstatus_record_tvAccuracy );
143
+ tvAccuracy .setText (getResources ().getString (R .string .various_waiting_gps_fix )
144
+ .replace ("{0}" , Long .toString (fixCount ))
145
+ .replace ("{1}" , Long .toString (satCount )));
146
+
147
+ ((ImageView ) findViewById (R .id .gpsstatus_record_imgSatIndicator )).setImageResource (R .drawable .sat_indicator_unknown );
148
+ }
149
+
150
+ Log .v (TAG , "Found " + satCount + " satellites. " + fixCount + " used in fix." );
151
+ }
152
+ };
153
+
126
154
@ Override
127
155
public void onLocationChanged (Location location ) {
128
156
// first of all we check if the time from the last used fix to the current fix is greater than the logging interval
@@ -136,20 +164,14 @@ public void onLocationChanged(Location location) {
136
164
manageRecordingIndicator (true );
137
165
}
138
166
139
- //TODO: get number of satellites used and visible.
140
- //Log.v(TAG, "Found " + satCount + " satellites. " + fixCount + " used in fix.
141
-
142
167
TextView tvAccuracy = findViewById (R .id .gpsstatus_record_tvAccuracy );
143
168
if (location .hasAccuracy ()) {
144
169
Log .d (TAG , "location accuracy: " + ACCURACY_FORMAT .format (location .getAccuracy ()));
145
170
tvAccuracy .setText (getResources ().getString (R .string .various_accuracy_with_sats )
146
171
.replace ("{0}" , ACCURACY_FORMAT .format (location .getAccuracy ()))
147
172
.replace ("{1}" , getResources ().getString (R .string .various_unit_meters ))
148
- //TODO: use the number of satellites used and visible
149
- //.replace("{2}", Long.toString(fixCount))
150
- //.replace("{3}", Long.toString(satCount)));
151
- .replace ("{2}" , "?" )
152
- .replace ("{3}" , "?" ));
173
+ .replace ("{2}" , Long .toString (fixCount ))
174
+ .replace ("{3}" , Long .toString (satCount )));
153
175
154
176
manageSatelliteStatusIndicator ((int ) location .getAccuracy ());
155
177
0 commit comments