【发布时间】:2011-05-26 20:21:10
【问题描述】:
我只需要监控 GPS 接收器或适配器的状态,如果用户手动禁用 gps,我的应用程序将无法工作...
尝试使用此链接中的信息,但没有帮助 - How can I monitor the status of the GPS adapter using Android SDK?
有什么想法吗?
【问题讨论】:
我只需要监控 GPS 接收器或适配器的状态,如果用户手动禁用 gps,我的应用程序将无法工作...
尝试使用此链接中的信息,但没有帮助 - How can I monitor the status of the GPS adapter using Android SDK?
有什么想法吗?
【问题讨论】:
要检查 GPS 的可用性,您可以使用以下代码
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//gps off. User turned the GPS off manually.
}
【讨论】:
boolean gpSstate = locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER);
boolean networkState =locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!gpsState && !networkState) {// no GPS Service }
【讨论】: