我始终看到 GPS 图标是什么意思?

iam*_*end 1 gps android locationmanager

我编写了我的自定义位置管理器,每 30 秒检查一次用户位置的更新。代码运行良好,即我正在接收用户所在位置的更新。但问题是 GPS 图标始终在顶部的状态栏上可见。我猜它应该在 30 秒内只可见一次。这是正常的还是我做错了什么?

在此处输入图片说明

public volatile Double mLatitude = 0.0;
public volatile Double mLongitude = 0.0;

int minTime = 30000;
float minDistance = 0;
MyLocationListener myLocListener = new MyLocationListener();
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

Criteria criteria = new Criteria();
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setSpeedRequired(false);

String bestProvider = locationManager.getBestProvider(criteria, false);
locationManager.requestSingleUpdate(criteria, myLocListener, null);     
locationManager.requestLocationUpdates(bestProvider, minTime, minDistance, myLocListener);


private class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location loc)
        {
            if (loc != null) {
                //Do something knowing the location changed by the distance you requested
                mLatitude = loc.getLatitude();
                mLongitude = loc.getLongitude();
                Toast.makeText(mContext, "Location Changed! "+Double.toString(mLatitude)+" "+Double.toString(mLongitude), Toast.LENGTH_LONG).show();
            }

        }

        @Override
        public void onProviderDisabled(String arg0)
        {
            //Do something here if you would like to know when the provider is disabled by the user
            Toast.makeText(mContext, "Provider Disabled! "+Double.toString(mLatitude)+" "+Double.toString(mLongitude), Toast.LENGTH_LONG).show();

        }

        @Override
        public void onProviderEnabled(String arg0)
        {
            //Do something here if you would like to know when the provider is enabled by the user
            Toast.makeText(mContext, "Provider Enabled! "+Double.toString(mLatitude)+" "+Double.toString(mLongitude), Toast.LENGTH_LONG).show();

        }

        @Override
        public void onStatusChanged(String arg0, int arg1, Bundle arg2)
        {
            //Do something here if you would like to know when the provider status changes
            Toast.makeText(mContext, "Provider Status Changed! "+Double.toString(mLatitude)+" "+Double.toString(mLongitude), Toast.LENGTH_LONG).show();

        }
    }
Run Code Online (Sandbox Code Playgroud)

Gab*_*han 6

只要 1 个或多个应用程序为 GPS 提供商调用 requestLocationUpdates,GPS 就会保持开启状态。它不会在请求之间关闭。它不能-这样做会导致它失去卫星锁定,这将导致它必须重新建立。有时这需要超过 30 秒。因此,GPS 将保持开启状态,直到您取消注册 GPS 事件。