3

I am trying to detect whether the GPS in the phone is being used or not. So far, GpsStatus listener has been working fine for my Android devices. In the case of SDK 24, I have been using GnssStatus.callback. I have checked that callback is successfully registered. However, still I am not receiving any notification when Google Map uses GPS. My callback function is the following

public final GnssStatus.Callback gnssStatusListener = new GnssStatus.Callback() {
    @Override
    public void onStarted() {
        Log.d(APP_NAME,"GPS started");
    }

    @Override
    public void onStopped() {
        Log.d(APP_NAME,"GPS stopped");
    }

    @Override
    public void onSatelliteStatusChanged(GnssStatus status) {
        Log.d(APP_NAME,"GPS started"+status.toString());
    }
};

The callback function is registered inside a permission check block.

if(ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED){
    if(Build.VERSION.SDK_INT==24){
        manager.registerGnssStatusCallback(gnssStatusListener);
    }
    Log.d(APP_NAME, "ACCESS_FINE_LOCATION premission granted");
}

I am not quite sure what is happening. Thanks a lot for your help.

Adrian Forsius
  • 1,437
  • 2
  • 19
  • 29
Shathil
  • 31
  • 1
  • 3
  • When you say "is being used" do you mean, "is being accessed by apps other than my own"? Or do you mean "is switched on?" – Saik Caskey May 12 '17 at 11:44
  • @SaikCaskey, thanks. Yes I mean the GPS is being accessed by any other app than my own. – Shathil May 13 '17 at 12:09
  • Hmmm I'm not sure that you can do this at all, and even at that, you'll only get the hardware updates here - so be aware, if you are sitting at your computer that your callbacks probably won't be called unless you mock your GPS provider to test. You need a satellite fix, which is slightly different to what most people consider as "GPS" on their phones - you could be in a bad area. Try other apps that do satellite fixing and see if they work – Saik Caskey May 19 '17 at 10:27

0 Answers0