Java Code Examples for android.location.GpsStatus#GPS_EVENT_SATELLITE_STATUS

The following examples show how to use android.location.GpsStatus#GPS_EVENT_SATELLITE_STATUS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidLocationManager.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void onGpsStatusChanged(int event) {
    boolean isGPSFix = false;
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (lastLocation != null) {
                isGPSFix = (SystemClock.elapsedRealtime() - lastLocationMillis) < 10000;
            }
            if (isGPSFix) { // A fix has been acquired.
                setLocationManagerStatus(AVAILABLE);
            } else { // The fix has been lost.
                setLocationManagerStatus(TEMPORARILY_UNAVAILABLE);
            }
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            setLocationManagerStatus(AVAILABLE);
            break;
    }
}
 
Example 2
Source File: GpsStatusInfo.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks if there fix is still there based on the last picked location.
 *
 * @param hasFix                   fix state previous to the check.
 * @param lastLocationUpdateMillis the millis of the last picked location.
 * @param event                    the Gps status event triggered.
 * @return <code>true</code>, if it has fix.
 */
@SuppressWarnings("nls")
public static boolean checkFix(boolean hasFix, long lastLocationUpdateMillis, int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            long diff = SystemClock.elapsedRealtime() - lastLocationUpdateMillis;
            if (GPLog.LOG_ABSURD)
                GPLog.addLogEntry("GPSSTATUSINFO", "gps event diff: " + diff);
            if (diff < FIX_TIME_INTERVAL_CHECK) {
                if (!hasFix) {
                    hasFix = true;
                }
            } else {
                if (hasFix) {
                    hasFix = false;
                }
            }
            break;
    }
    return hasFix;
}
 
Example 3
Source File: DiagnosticsActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            try {
                gpsStatus = lm.getGpsStatus(gpsStatus);
            } catch (SecurityException e) {
                e.printStackTrace();
            }

            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            // Do something.
            break;
    }
}
 
Example 4
Source File: GpsEventSource.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event)
{
    switch(event)
    {
        case GpsStatus.GPS_EVENT_STARTED:
        case GpsStatus.GPS_EVENT_STOPPED:
            mHasGPSFix = false;
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            mHasGPSFix = true;
            break;
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            break;
    }

    for (GpsEventListener listener : mListeners) {
        listener.onGpsStatusChanged(event);
    }
}
 
Example 5
Source File: TrackerService.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_STARTED:
        case GpsStatus.GPS_EVENT_STOPPED:
            mHasGPSFix = false;
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            mHasGPSFix = true;
            break;

        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            mSatellitesCount = 0;

            for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) {
                if (sat.usedInFix()) {
                    mSatellitesCount++;
                }
            }
            break;
    }
}
 
Example 6
Source File: LocationHelper.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
public void onGpsStatusChanged(int event) {

            if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
                try {
                    // Check number of satellites in list to determine fix state
                    GpsStatus status = myLocationManager.getGpsStatus(null);
                    Iterable<GpsSatellite> satellites = status.getSatellites();

                    sat_count = 0;

                    Iterator<GpsSatellite> satI = satellites.iterator();
                    while (satI.hasNext()) {
                        GpsSatellite satellite = satI.next();
                        Log.d(LogUtils.generateTag(this), "Satellite: snr=" + satellite.getSnr() + ", elevation=" + satellite.getElevation());
                        sat_count++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    sat_count = min_gps_sat_count + 1;
                }

                Log.d(LogUtils.generateTag(this), "#### sat_count = " + sat_count);

            }
        }
 
Example 7
Source File: LocationHelper.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
public void onGpsStatusChanged(int event) {

            if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
                try {
                    // Check number of satellites in list to determine fix state
                    GpsStatus status = myLocationManager.getGpsStatus(null);
                    Iterable<GpsSatellite> satellites = status.getSatellites();

                    sat_count = 0;

                    Iterator<GpsSatellite> satI = satellites.iterator();
                    while (satI.hasNext()) {
                        GpsSatellite satellite = satI.next();
                        Log.d(LogUtils.generateTag(this), "Satellite: snr=" + satellite.getSnr() + ", elevation=" + satellite.getElevation());
                        sat_count++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    sat_count = min_gps_sat_count + 1;
                }

                Log.d(LogUtils.generateTag(this), "#### sat_count = " + sat_count);

            }
        }
 
Example 8
Source File: GPSListenersMaker.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        // first time fix
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            break;
        // satellite status changed
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
            int maxSatellites = gpsStatus.getMaxSatellites();
            Iterator iters = gpsStatus.getSatellites().iterator();
            int count = 0;
            while (iters.hasNext() && count <= maxSatellites) {
                iters.next();
                count++;
            }
            mSatellitesNum = count;
            break;
        case GpsStatus.GPS_EVENT_STARTED:
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            break;
        default:
            break;
    }
}
 
Example 9
Source File: GpsStatusService.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
        // Count fixed/visible satellites
        int fixed = 0;
        int visible = 0;
        LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        for (GpsSatellite sat : lm.getGpsStatus(null).getSatellites()) {
            visible++;
            if (sat.usedInFix())
                fixed++;
        }

        // Persist fixed/visible satellites
        Log.i(TAG, "Satellites fixed/visible=" + fixed + "/" + visible);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GpsStatusService.this);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(SettingsFragment.PREF_SATS_FIXED, fixed);
        editor.putInt(SettingsFragment.PREF_SATS_VISIBLE, visible);
        editor.apply();

        // Send state changed intent
        Intent intent = new Intent(GpsStatusService.this, BackgroundService.class);
        intent.setAction(BackgroundService.ACTION_STATE_CHANGED);
        startService(intent);
    }
}
 
Example 10
Source File: GPSLocationProvider.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
public void onGpsStatusChanged(int event) {
	
	if (passiveMode) {
		return;
	}
	
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (mLastLocation != null)
                isGpsFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;

            if (isGpsFix) { // A fix has been acquired.
            	filterNonGPSFix = true;
                // Do something.
            } else { // The fix has been lost.
            	filterNonGPSFix = false;
                // Do something.
            }

            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            // Do something.
        	isGpsFix = true;
        	filterNonGPSFix = true;

            break;
    }
}
 
Example 11
Source File: GpsConnection.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
public void onGpsStatusChanged(int event) {
    // Logger.i(TAG, "onGpsStatusChanged(" + event + ")");
    try {
        if (locationManager == null)
            return;

        if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), first fix");
        } else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), satellite status");
            if (gpsStatus == null)
                gpsStatus = locationManager.getGpsStatus(null);
            else
                gpsStatus = locationManager.getGpsStatus(gpsStatus);

            LocationState.onGpsStatusChanged(event, gpsStatus);
        } else if (event == GpsStatus.GPS_EVENT_STARTED) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), started");
            LocationState.onGpsStatusChanged(event, null);
        } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), stopped");
            LocationState.onGpsStatusChanged(event, null);
            // XXX this happen for unknown reason!
        }
    } catch (Exception e) {
        Logger.e(TAG, "onGpsStatusChanged(" + event + ")", e);
    }
}
 
Example 12
Source File: GPSApplication.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged(final int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            // TODO: get here the status of the GPS, and save into a GpsStatus to be used for satellites visualization;
            // Use GpsStatus getGpsStatus (GpsStatus status)
            // https://developer.android.com/reference/android/location/LocationManager.html#getGpsStatus(android.location.GpsStatus)
            updateSats();
            break;
    }
}
 
Example 13
Source File: GpsActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
	// ��ȡ��ǰ״̬
	gpsstatus = locationManager.getGpsStatus(null);
	switch (event) {
	// ��һ�ζ�λʱ���¼�
	case GpsStatus.GPS_EVENT_FIRST_FIX:
		break;
	// ��ʼ��λ���¼�
	case GpsStatus.GPS_EVENT_STARTED:
		break;
	// ����GPS����״̬�¼�
	case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
		Toast.makeText(GpsActivity.this, "GPS_EVENT_SATELLITE_STATUS", Toast.LENGTH_SHORT).show();
		Iterable<GpsSatellite> allSatellites = gpsstatus.getSatellites();
		Iterator<GpsSatellite> it = allSatellites.iterator();
		int count = 0;
		while (it.hasNext()) {
			count++;
		}
		Toast.makeText(GpsActivity.this, "Satellite Count:" + count, Toast.LENGTH_SHORT).show();
		break;
	// ֹͣ��λ�¼�
	case GpsStatus.GPS_EVENT_STOPPED:
		Log.d(TAG, "GPS_EVENT_STOPPED");
		break;
	}
}
 
Example 14
Source File: MainActivity.java    From SpeedMeter with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged (int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
            int satsInView = 0;
            int satsUsed = 0;
            Iterable<GpsSatellite> sats = gpsStatus.getSatellites();
            for (GpsSatellite sat : sats) {
                satsInView++;
                if (sat.usedInFix()) {
                    satsUsed++;
                }
            }
            satellite.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView));
            if (satsUsed == 0) {
                fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play));
                data.setRunning(false);
                status.setText("");
                stopService(new Intent(getBaseContext(), GpsServices.class));
                fab.setVisibility(View.INVISIBLE);
                refresh.setVisibility(View.INVISIBLE);
                accuracy.setText("");
                status.setText(getResources().getString(R.string.waiting_for_fix));
                firstfix = true;
            }
            break;

        case GpsStatus.GPS_EVENT_STOPPED:
            if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                showGpsDisabledDialog();
            }
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            break;
    }
}
 
Example 15
Source File: LocationState.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
static void onGpsStatusChanged(int event, GpsStatus gpsStatus) {
    if (mListeners == null || mListeners.size() == 0)
        return;

    if (event == GpsStatus.GPS_EVENT_STARTED || event == GpsStatus.GPS_EVENT_STOPPED) {
        for (int i = 0; i < mListeners.size(); i++) {
            mListeners.get(i).onStatusChanged(LocationManager.GPS_PROVIDER,
                    event == GpsStatus.GPS_EVENT_STARTED ? 2 : 1, null);
        }
    } else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
        ArrayList<SatellitePosition> pos = null;
        if (gpsStatus != null) {
            pos = new ArrayList<>();
            Iterator<GpsSatellite> enuSat = gpsStatus.getSatellites().iterator();
            // clear sats count
            mSatsCount.x = 0;
            mSatsCount.y = 0;
            while (enuSat.hasNext()) {
                GpsSatellite sat = enuSat.next();
                // pos.add(enuPos.nextElement());
                SatellitePosition satPos = new SatellitePosition();
                satPos.azimuth = sat.getAzimuth();
                satPos.elevation = sat.getElevation();
                satPos.prn = sat.getPrn();
                satPos.snr = (int) sat.getSnr();
                satPos.fixed = sat.usedInFix();
                if (satPos.fixed)
                    mSatsCount.x++;
                mSatsCount.y++;
                pos.add(satPos);
            }
        }
        postGpsSatelliteChange(pos);
    }
}
 
Example 16
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    if (enableMockLocations && BuildConfig.DEBUG)
        return;

    switch (event) {
        case GpsStatus.GPS_EVENT_STARTED:
            mGpsStatus = GPS_SEARCHING;
            mTSats = 0;
            mFSats = 0;
            updateGpsStatus();
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            mContinuous = false;
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            tearTrack();
            mGpsStatus = GPS_OFF;
            mTSats = 0;
            mFSats = 0;
            updateGpsStatus();
            break;
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (mLocationManager == null)
                return;
            try {
                GpsStatus status = mLocationManager.getGpsStatus(null);
                Iterator<GpsSatellite> it = status.getSatellites().iterator();
                mTSats = 0;
                mFSats = 0;
                while (it.hasNext()) {
                    mTSats++;
                    GpsSatellite sat = it.next();
                    if (sat.usedInFix())
                        mFSats++;
                }
                if (mLastLocationMillis >= 0) {
                    if (SystemClock.elapsedRealtime() - mLastLocationMillis < 3000) {
                        mGpsStatus = GPS_OK;
                    } else {
                        if (mContinuous)
                            tearTrack();
                        mGpsStatus = GPS_SEARCHING;
                    }
                }
                updateGpsStatus();
            } catch (SecurityException e) {
                logger.error("Failed to update gps status", e);
            }
            break;
    }
}
 
Example 17
Source File: GPSController.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 4 votes vote down vote up
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;
    }
 
Example 18
Source File: LocationService.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGpsStatusChanged(int event)
{
	if (enableMockLocations)
		return;

	switch (event)
	{
		case GpsStatus.GPS_EVENT_STARTED:
			updateProvider(LocationManager.GPS_PROVIDER, true);
			updateGpsStatus(GPS_SEARCHING, 0, 0);
			break;
		case GpsStatus.GPS_EVENT_FIRST_FIX:
			isContinous = false;
			break;
		case GpsStatus.GPS_EVENT_STOPPED:
			tearTrack();
			updateGpsStatus(GPS_OFF, 0, 0);
			updateProvider(LocationManager.GPS_PROVIDER, false);
			break;
		case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
			if (locationManager == null)
				return;
			GpsStatus gpsStatus = locationManager.getGpsStatus(null);
			Iterator<GpsSatellite> it = gpsStatus.getSatellites().iterator();
			int tSats = 0;
			int fSats = 0;
			while (it.hasNext())
			{
				tSats++;
				GpsSatellite sat = (GpsSatellite) it.next();
				if (sat.usedInFix())
					fSats++;
			}
			if (SystemClock.elapsedRealtime() - lastLocationMillis < 3000)
			{
				updateGpsStatus(GPS_OK, fSats, tSats);
			}
			else
			{
				tearTrack();
				updateGpsStatus(GPS_SEARCHING, fSats, tSats);
			}
			break;
	}
}