How to test GPS status?

前端 未结 2 1328
南笙
南笙 2021-01-29 01:14

I now create an app to detect the location of device through GPS, I have problem with GPS status, I look through the GpsStatus.Listener but it\'s complicated since I\'m a newbie

2条回答
  •  梦毁少年i
    2021-01-29 01:30

    When the onGpsStatusChanged() is called from the framework it means that there is a valid gps status update. Use getGpsStatus() to retrieve the latest GPS status updates.

    public void onGpsStatusChanged(int event) {
            if (event == GpsStatus.GPS_EVENT_STARTED) {
                Log.d(TAG , "GPS event started ");
    
            } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
                Log.d(TAG , "GPS event stopped ");
    
            } else if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {
    
                GpsStatus gs = locationManager.getGpsStatus(null);
    

    You can use the above snippet. Note that some of the data you want is in the GpsStatus structure.

    The rest of the info you require like new location can be obtained from the onLocationChanged() callback.

提交回复
热议问题