Last active
September 5, 2017 11:43
-
-
Save danikx/c020ae48a70b616b999b647283641ba9 to your computer and use it in GitHub Desktop.
android listen gps status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final LocationManager lm = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); | |
if (Build.VERSION.SDK_INT >= 24) { | |
lm.registerGnssStatusCallback(new GnssStatus.Callback() { | |
@Override public void onStarted() { | |
super.onStarted(); | |
Log.d(TAG, "gps started"); | |
updateGpsView(); | |
} | |
}); | |
} else { | |
lm.addGpsStatusListener(event -> { | |
switch (event) { | |
case GPS_EVENT_STARTED: | |
Log.d(TAG, "gps started"); | |
updateGpsView(); | |
break; | |
case GPS_EVENT_STOPPED: | |
Log.d(TAG, "gps stopped"); | |
updateGpsView(); | |
break; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment