我的应用显示位置长而LAT,并且运行良好
但是当我必须检测到位置传感器状态时就像,工作,错误,...它有一些问题
我的想法是此代码:
Case LocationSensor1.Sensor.State of
TSensorState.Added : label5.Text:='2';
TSensorState.Removed : label5.Text:='3';
TSensorState.Initializing : label5.Text:='4';
TSensorState.Ready : label5.Text:='ready';
TSensorState.NoData : label5.Text:='6';
TSensorState.AccessDenied : label5.Text:='7';
TSensorState.Error : label5.Text:='8';
else label5.Text:='error';
End;
但是,当我打开或关闭GPS时,每次都是ready
如何检测并显示GPS传感器状态?
您必须创建一个扩展LocationListener
类的类。您将通过两个回调函数通知您GPS状态更改:onProviderEnabled
,当启用GPS时将调用,并且在禁用GP时将调用onProviderDisabled
。
要注册您的侦听器,请使用((LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE)).requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, myLocationListener);
。