android.location.GpsSatellite Java Examples

The following examples show how to use android.location.GpsSatellite. 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: DiagnosticsActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private void probeGps() {
    StringBuilder sb = new StringBuilder();
    if (currentLocation != null) {
        sb.append("Current Location:\n");
        sb.append(currentLocation.getLatitude()).append(",").append(currentLocation.getLongitude()).append("\n");
        sb.append("Alt ").append(currentLocation.getAltitude()).append("\n");
        sb.append("Accuracy ").append(currentLocation.getAccuracy()).append("\n");
        sb.append("Bearing ").append(currentLocation.getBearing()).append("\n");
        sb.append("Speed ").append(currentLocation.getSpeed()).append("\n\n");
    }
    try {
        if (gpsStatus != null) {
            Iterator<GpsSatellite> iterator = gpsStatus.getSatellites().iterator();
            while (iterator.hasNext()) {
                GpsSatellite next = iterator.next();
                sb.append("Sat PRN " + next.getPrn() + " Elevation " + next.getElevation() + " Azimuth " + next.getAzimuth() + "SNR " + next.getSnr()).append("\n");
            }
        }
    } catch (Exception e) {
        sb.append(e.toString());
    }
    output.setText(sb.toString());
}
 
Example #2
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 #3
Source File: e.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void b()
{
    m = 0;
    l = 0;
    GpsStatus gpsstatus = b.getGpsStatus(null);
    if (gpsstatus != null)
    {
        int i1 = gpsstatus.getMaxSatellites();
        Iterator iterator = gpsstatus.getSatellites().iterator();
        if (iterator != null)
        {
            while (iterator.hasNext() && l <= i1) 
            {
                l = 1 + l;
                if (((GpsSatellite)iterator.next()).usedInFix())
                {
                    m = 1 + m;
                }
            }
        }
    }
}
 
Example #4
Source File: GpsStatusInfo.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
private void analyze() {
    if (satellites != null) {
        return;
    }
    satellites = status.getSatellites().iterator();
    maxSatellites = status.getMaxSatellites();

    satCount = 0;
    satUsedInFixCount = 0;
    while (satellites.hasNext()) {
        GpsSatellite satellite = satellites.next();
        satCount++;
        if (satellite.usedInFix()) {
            satUsedInFixCount++;
        }
    }
}
 
Example #5
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 #6
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 #7
Source File: HookLocationFaker.java    From PokeFaker with MIT License 6 votes vote down vote up
public static List<GpsSatellite> fetchGpsSatellites() {
    if (cacheGpsSatelliteList == null) {
        cacheGpsSatelliteList = new ArrayList<>();
        for (FakeGpsSatellite fake: staticList) {
            GpsSatellite real = ((GpsSatellite) XposedHelpers.newInstance(GpsSatellite.class, fake.mPrn));
            XposedHelpers.setBooleanField(real, "mValid", fake.mValid);
            XposedHelpers.setBooleanField(real, "mUsedInFix", fake.mUsedInFix);
            XposedHelpers.setBooleanField(real, "mHasAlmanac", fake.mHasAlmanac);
            XposedHelpers.setBooleanField(real, "mHasEphemeris", fake.mHasEphemeris);
            XposedHelpers.setFloatField(real, "mSnr", fake.mSnr);
            XposedHelpers.setFloatField(real, "mElevation", fake.mElevation);
            XposedHelpers.setFloatField(real, "mAzimuth", fake.mAzimuth);
            cacheGpsSatelliteList.add(real);
        }
    }
    return cacheGpsSatelliteList;

}
 
Example #8
Source File: HookLocationFaker.java    From PokeFaker with MIT License 6 votes vote down vote up
private static String satelliteToString(GpsSatellite s) {
    StringBuilder sb = new StringBuilder();
    if (s != null) {
        sb.append("GpsSatellite[" +
                "usedInFix = " + s.usedInFix() + ", " +
                "hasAlmanac = " + s.hasAlmanac() + ", " +
                "hasEphemeris = " + s.hasEphemeris() + ", " +
                "prn = " + s.getPrn() + ", " +
                "snr = " + s.getSnr() + ", " +
                "elevation = " + s.getElevation() + ", " +
                "azimuth = " + s.getAzimuth() + "]");
    } else {
        sb.append("GpsSatellite[null]");
    }
    return sb.toString();
}
 
Example #9
Source File: PasvLocListenerService.java    From satstat with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
	GpsStatus status = mLocationManager.getGpsStatus(null);
	int satsUsed = 0;
	Iterable<GpsSatellite> sats = status.getSatellites();
	for (GpsSatellite sat : sats) {
		if (sat.usedInFix()) {
			satsUsed++;
		}
	}
	if (satsUsed == 0) {
		if (mStatus != GPS_INACTIVE)
			mStatus = GPS_SEARCH;
		showStatusNoLocation();
	}
}
 
Example #10
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@SuppressLint("MissingPermission")
@Override
public void onGpsStatusChanged(int event) {
    int satellites = 0;
    int satellitesInFix = 0;
    int timeToFix = mLocationManager.getGpsStatus(null).getTimeToFirstFix();
    for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) {
        if (sat.usedInFix()) {
            satellitesInFix++;
        }
        satellites++;
    }
    LogUtil.i(TAG, satellites + " Used In Last Fix (" + satellitesInFix + ")");
    if (satellites > 10) {
        mGpsImg.setImageResource(R.drawable.gps_1);
    } else if (satellites > 0) {
        mGpsImg.setImageResource(R.drawable.gps_2);
    } else {
        mGpsImg.setImageResource(R.drawable.gps_3);
    }
}
 
Example #11
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    int satellites = 0;
    int satellitesInFix = 0;
    int timeToFix = mLocationManager.getGpsStatus(null).getTimeToFirstFix();
    for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) {
        if (sat.usedInFix()) {
            satellitesInFix++;
        }
        satellites++;
    }
    LogUtil.i(TAG, satellites + " Used In Last Fix (" + satellitesInFix + ")");
    if (satellites > 10) {
        mGpsImg.setImageResource(R.drawable.ic_gps_1);
    } else if (satellites > 0) {
        mGpsImg.setImageResource(R.drawable.ic_gps_2);
    } else {
        mGpsImg.setImageResource(R.drawable.ic_gps_3);
    }
}
 
Example #12
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    int satellites = 0;
    int satellitesInFix = 0;
    for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) {
        if (sat.usedInFix()) {
            satellitesInFix++;
        }
        satellites++;
    }
    LogUtil.i(TAG, "GpsStatus.Listener: " + satellites + " Used In Last Fix (" + satellitesInFix + ")");
    if (satellites > 10) {
        mGpsImg.setImageResource(R.drawable.ic_gps_1);
    } else if (satellites > 0) {
        mGpsImg.setImageResource(R.drawable.ic_gps_2);
    } else {
        mGpsImg.setImageResource(R.drawable.ic_gps_3);
    }
}
 
Example #13
Source File: MainActivity.java    From satstat with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Called when the status of the GPS changes. Updates GPS display.
   */
  public void onGpsStatusChanged (int event) {
GpsStatus status = locationManager.getGpsStatus(null);
int satsInView = 0;
int satsUsed = 0;
Iterable<GpsSatellite> sats = status.getSatellites();
for (GpsSatellite sat : sats) {
	satsInView++;
	if (sat.usedInFix()) {
		satsUsed++;
	}
}

if (gpsSectionFragment != null) {
  		gpsSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
  	}
  	
if (mapSectionFragment != null) {
	mapSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
}
  }
 
Example #14
Source File: GpsStatusView.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	int cx = mW / 2;
	int cy = mH / 2;

	//Log.d("GpsStatusView", String.format("Drawing on a %dx%d canvas", w, h));

	canvas.translate(cx, cy);
	canvas.rotate(-mRotation);
	
	canvas.drawCircle(0, 0, mW * 0.37125f, gridBorderPaint);
	
	canvas.drawLine(-mW * 0.405f, 0, mW * 0.405f, 0, gridPaint);
	canvas.drawLine(0, -mH * 0.405f, 0, mH * 0.405f, gridPaint);
	
	canvas.drawCircle(0,  0,  mW * 0.405f, gridPaint);
	canvas.drawCircle(0,  0,  mW * 0.27f, gridPaint);
	canvas.drawCircle(0,  0,  mW * 0.135f, gridPaint);
	
	canvas.drawPath(northArrow, northPaint);
	
	canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_N),
			labelPathN, 0, -labelPaint.descent(), labelPaint);

	canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_S),
			labelPathS, 0, -labelPaint.descent(), labelPaint);

	canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_E),
			labelPathE, 0, -labelPaint.descent(), labelPaint);

	canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_W),
			labelPathW, 0, -labelPaint.descent(), labelPaint);
	
	if (mSats != null) {
		for (GpsSatellite sat : mSats) {
			drawSat(canvas, sat.getPrn(), sat.getAzimuth(), sat.getElevation(), sat.getSnr(), sat.usedInFix());
		}
	}
}
 
Example #15
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 #16
Source File: GpsSectionFragment.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called by {@link MainActivity} when the status of the GPS changes. Updates GPS display.
 */
public void onGpsStatusChanged(GpsStatus status, int satsInView, int satsUsed, Iterable<GpsSatellite> sats) {
	gpsSats.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView));
	gpsTtff.setText(String.valueOf(status.getTimeToFirstFix() / 1000));
	gpsStatusView.showSats(sats);
	gpsSnrView.showSats(sats);
}
 
Example #17
Source File: MapSectionFragment.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called by {@link MainActivity} when the status of the GPS changes. Updates GPS display.
 */
public void onGpsStatusChanged(GpsStatus status, int satsInView, int satsUsed, Iterable<GpsSatellite> sats) {
	if (satsUsed == 0) {
		Location location = providerLocations.get(LocationManager.GPS_PROVIDER);
		if (location != null)
			markLocationAsStale(location);
		applyLocationProviderStyle(this.getContext(), LocationManager.GPS_PROVIDER, Const.LOCATION_PROVIDER_GRAY);
	}
}
 
Example #18
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 #19
Source File: GpsSnrView.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Redraws the SNR view.
 * <p>
 * This method is called whenever the view needs to be redrawn. Besides the
 * usual cases of view creation/recreation, this also occurs when the
 * {@link #showSats(Iterable)} has been called to indicate new SNR data is
 * available.
 */
@Override
protected void onDraw(Canvas canvas) {
	initializeGrid();
	
	// draw the SNR bars
	if (mSats != null)
		for (GpsSatellite sat : mSats)
			drawSat(canvas, sat.getPrn(), sat.getSnr(), sat.usedInFix());
	
	// draw the grid on top
	drawGrid(canvas);
}
 
Example #20
Source File: GPSApplication.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
public void updateSats() {
    try {
        if ((mlocManager != null) && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
            GpsStatus gs = mlocManager.getGpsStatus(null);
            int sats_inview = 0;    // Satellites in view;
            int sats_used = 0;      // Satellites used in fix;

            if (gs != null) {
                Iterable<GpsSatellite> sats = gs.getSatellites();
                for (GpsSatellite sat : sats) {
                    sats_inview++;
                    if (sat.usedInFix()) sats_used++;
                    //Log.w("myApp", "[#] GPSApplication.java - updateSats: i=" + i);
                }
                _NumberOfSatellites = sats_inview;
                _NumberOfSatellitesUsedInFix = sats_used;
            } else {
                _NumberOfSatellites = NOT_AVAILABLE;
                _NumberOfSatellitesUsedInFix = NOT_AVAILABLE;
            }
        } else {
            _NumberOfSatellites = NOT_AVAILABLE;
            _NumberOfSatellitesUsedInFix = NOT_AVAILABLE;
        }
    } catch (NullPointerException e) {
        _NumberOfSatellites = NOT_AVAILABLE;
        _NumberOfSatellitesUsedInFix = NOT_AVAILABLE;
        //Log.w("myApp", "[#] GPSApplication.java - updateSats: Caught NullPointerException: " + e);
    }
    //Log.w("myApp", "[#] GPSApplication.java - updateSats: Total=" + _NumberOfSatellites + " Used=" + _NumberOfSatellitesUsedInFix);
}
 
Example #21
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 #22
Source File: HookLocationFaker.java    From PokeFaker with MIT License 5 votes vote down vote up
private void hook_gpsStatusUpdate(XC_LoadPackage.LoadPackageParam lpparam) {
        if (!lpparam.packageName.equals("com.nianticlabs.pokemongo")) return;

        XposedHelpers.findAndHookMethod(
                    "com.nianticlabs.nia.location.NianticLocationManager",
                    lpparam.classLoader,
                    "gpsStatusUpdate",
                    int.class,
                    GpsSatellite[].class,
                    new XC_MethodReplacement() {
                        @Override
                        protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
//                            int timeToFix = ((int) param.args[0]);
//                            GpsSatellite[] satellites = ((GpsSatellite[]) param.args[1]);
//                            for (GpsSatellite s: satellites) {
//                                XposedBridge.log(satelliteToString(s));
//                            }
                            Location locationGps = mLocationHolder.pollLocation("gps");
                            Location locationNetwork = mLocationHolder.pollLocation("network");
                            call_updateLocation(locationGps);
                            call_updateLocation(locationNetwork);

//                            List<GpsSatellite> fakeSatelliteList = FakeGpsSatellite.fetchGpsSatellites();
//                            GpsSatellite[] fakeSatellites = new GpsSatellite[fakeSatelliteList.size()];
//                            for (int i = 0; i < fakeSatelliteList.size(); i++) {
//                                fakeSatellites[i] = fakeSatelliteList.get(i);
//                            }
//                            param.args[1] = fakeSatellites;
                            return null;
                        }
                    }
        );
    }
 
Example #23
Source File: JSONHelper.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 5 votes vote down vote up
/**
 * Converts GpsStatus into JSON.
 * @param gpsStatus Send a GpsStatus whenever the GPS fires
 * @return JSON representation of the satellite data
 */
public static String satelliteDataJSON(GpsStatus gpsStatus){

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    try {
        json.put("provider", SATELLITE_PROVIDER);
        json.put("timestamp", calendar.getTimeInMillis());

        if(gpsStatus.getSatellites() != null) {
            int count = 0;
            final int timeToFirstFix = gpsStatus.getTimeToFirstFix();

            for(GpsSatellite sat: gpsStatus.getSatellites() ){
                final JSONObject satelliteInfo = new JSONObject();

                satelliteInfo.put("PRN", sat.getPrn());
                satelliteInfo.put("timeToFirstFix", timeToFirstFix);
                satelliteInfo.put("usedInFix", sat.usedInFix());
                satelliteInfo.put("azimuth", sat.getAzimuth());
                satelliteInfo.put("elevation", sat.getElevation());
                satelliteInfo.put("hasEphemeris", sat.hasEphemeris());
                satelliteInfo.put("hasAlmanac", sat.hasAlmanac());
                satelliteInfo.put("SNR", sat.getSnr());

                json.put(Integer.toString(count), satelliteInfo);

                count++;
            }
        }
    }
    catch (JSONException exc){
        logJSONException(exc);
    }

    return json.toString();
}
 
Example #24
Source File: e.java    From letv with Apache License 2.0 5 votes vote down vote up
private void b() {
    this.m = 0;
    this.l = 0;
    GpsStatus gpsStatus = b.getGpsStatus(null);
    if (gpsStatus != null) {
        int maxSatellites = gpsStatus.getMaxSatellites();
        Iterator it = gpsStatus.getSatellites().iterator();
        if (it != null) {
            while (it.hasNext() && this.l <= maxSatellites) {
                this.l++;
                if (((GpsSatellite) it.next()).usedInFix()) {
                    this.m++;
                }
            }
        }
    }
}
 
Example #25
Source File: ActivityLocation.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
private void getLocation() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(mContext, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
        return;
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);
    locationManager.addGpsStatusListener(new GpsStatus.Listener() {
        @Override
        public void onGpsStatusChanged(int event) {
            switch (event) {
                case GpsStatus.GPS_EVENT_STARTED:
                    System.out.println("GPS_EVENT_STARTED");
                    mGpsCount.setText("0");
                    break;
                case GpsStatus.GPS_EVENT_FIRST_FIX:
                    System.out.println("GPS_EVENT_FIRST_FIX");
                    break;
                case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                    System.out.println("GPS_EVENT_SATELLITE_STATUS");
                    if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                    GpsStatus gpsStatus = locationManager.getGpsStatus(null);
                    Iterable<GpsSatellite> gpsSatellites = gpsStatus.getSatellites();
                    int count = 0;
                    Iterator iterator = gpsSatellites.iterator();
                    while (iterator.hasNext()) {
                        count++;
                        iterator.next();
                    }
                    mGpsCount.setText(count + "");
                    break;
                case GpsStatus.GPS_EVENT_STOPPED:
                    System.out.println("GPS_EVENT_STOPPED");
                    //gpsState.setText("已停止定位");
                    break;
            }
        }
    });
}
 
Example #26
Source File: SatelliteDataCollector.java    From DataLogger with MIT License 5 votes vote down vote up
private void logSatelliteInfo(Iterable<GpsSatellite> gpsSatellites){
    int satCounter = 0;

    // System nanoseconds since boot, including time spent in sleep.
    long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;

    // System local time in millis
    long currentMillis = (new Date()).getTime();

    String message = String.format("%s", currentMillis) + ";"
            + String.format("%s", nanoTime) + ";"
            + String.format("%s", mNanosOffset);

    for(GpsSatellite satellite: gpsSatellites){
        satCounter++;

        // PRN (pseudo-random number) for the satellite.
        int prn = satellite.getPrn();

        // Signal to noise ratio for the satellite.
        float snr = satellite.getSnr();

        // Azimuth of the satellite in degrees.
        float azimuth = satellite.getAzimuth();

        // Elevation of the satellite in degrees.
        float elevation = satellite.getElevation();

        message += ";" + prn
                + ";" + snr
                + ";" + azimuth
                + ";" + elevation;
    }
    message += ";" + Integer.toString(satCounter);

    logger.log(message);
    logger.log(System.lineSeparator());
}
 
Example #27
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 #28
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;
	}
}
 
Example #29
Source File: GpsStatusView.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
public void showSats(Iterable<GpsSatellite> sats) {
	mSats = sats;
	invalidate();
}
 
Example #30
Source File: GpsSatelliteAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public GpsSatelliteAssert(GpsSatellite actual) {
  super(actual, GpsSatelliteAssert.class);
}