Android LocationServices - 检查位置是否已激活
Android LocationServices - Check if location is activated
我正在使用 LocationServices(使用 google 位置服务)在我的应用程序上实现位置管理器,我正在寻找一种方法来检查位置是否在设备系统上激活(在设置上) .我正在像这样连接到位置服务器:
private synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(mAppContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
private void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setSmallestDisplacement(SMALLEST_DISPLACEMENT);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
有没有办法检查系统位置设置的可用性?
可能有帮助
LocationManager locateManager=(LocationManager)getSystemService(LOCATION_SERVICE);
boolean enabled = locateManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// check if enabled and if not send user to the GPS settings
if (!enabled) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
} // Better solution would be to display a dialog and suggesting to go to the settings
我正在使用 LocationServices(使用 google 位置服务)在我的应用程序上实现位置管理器,我正在寻找一种方法来检查位置是否在设备系统上激活(在设置上) .我正在像这样连接到位置服务器:
private synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(mAppContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
private void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setSmallestDisplacement(SMALLEST_DISPLACEMENT);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
有没有办法检查系统位置设置的可用性?
可能有帮助
LocationManager locateManager=(LocationManager)getSystemService(LOCATION_SERVICE);
boolean enabled = locateManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// check if enabled and if not send user to the GPS settings
if (!enabled) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
} // Better solution would be to display a dialog and suggesting to go to the settings