简体   繁体   English

如何定期使用FusedLocationProviderApi知道Gps已关闭

[英]how to know Gps is off using FusedLocationProviderApi periodicaly

I am working in app where user location tracking all time and updated into server in background service, i update location to the server from onLocationChanged(Location location) @Override method. 我在应用程序中工作,用户位置一直跟踪并在后台服务中更新到服务器中,我从onLocationChanged(Location location)@Override方法更新服务器的位置。 I want hit server when location is not changed also. 我也想在不更改位置的情况下点击服务器。 is there any @Override method who is call when Gps is off?Mean,i want to notify the server that user's gps is off. Gps关闭时是否有任何@Override方法被调用?意思是,我想通知服务器用户的gps关闭。

You can detect GPS on/off event/status with GpsStatus.Listener and register it with the LocationManager. 您可以使用GpsStatus.Listener检测GPS开/关事件/状态,并在LocationManager中进行注册。

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.addGpsStatusListener(new android.location.GpsStatus.Listener()
{
    public void onGpsStatusChanged(int event)
    {
        switch(event)
        {
        case GPS_EVENT_STARTED:
            // do your tasks
            break;
        case GPS_EVENT_STOPPED:
            // do your tasks
            break;
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM