下面列出了android.location.GpsStatus#Listener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public GpsStatus.Listener getGpsStatusListener() {
return mStatusListener;
}
private static InitStatus setGPSStatusListener(){
// IMPORTANT: The GpsStatus.Listener Interface is deprecated at API 24.
// Reference: https://developer.android.com/reference/android/location/package-summary.html
_gpsStatusListener = new GpsStatus.Listener() {
@Override
public void onGpsStatusChanged(int event) {
Log.d(TAG, "GPS status changed.");
// Ignore if GPS_EVENT_STARTED or GPS_EVENT_STOPPED
if(!Thread.currentThread().isInterrupted() &&
(event == GpsStatus.GPS_EVENT_FIRST_FIX ||
event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) &&
_locationManager != null){
sendCallback(PluginResult.Status.OK,
JSONHelper.satelliteDataJSON(_locationManager.getGpsStatus(null)));
}
}
};
final InitStatus status = new InitStatus();
final Boolean gpsProviderEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if(gpsProviderEnabled){
try{
_locationManager.addGpsStatusListener(_gpsStatusListener);
}
// if the ACCESS_FINE_LOCATION permission is not present
catch(SecurityException exc){
status.success = false;
status.exception = exc.getMessage();
}
}
else {
//GPS not enabled
status.success = false;
status.error = ErrorMessages.GPS_UNAVAILABLE();
}
return status;
}