更新时间:2023-12-01 19:57:34
您可以听一个GpsStatus.Listener GPS状态 并与LocationManager注册。
You can listen the GPS status with a GpsStatus.Listener and register it with the 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;
}
}
});
您需要访问上下文(例如在活动或应用程序级)。
You need to have access to the context (for example in an "Activity" or "Application" class).